我如何使用 C# 代码从 google 驱动器 link 中知道原始文件名

How can i know the original file name from google drive link using c# code

我需要使用为文件提供的共享 link 提取存储在 Google 驱动器中的文件的原始文件名。

例如:我有一个文件名 Image.png 并且 link 将是:https://docs.google.com/presentation/d/1xYe18oaj2kpF6S--Vn_iJgdpKifTPvpkniZkV1-fpFc/edit?usp=sharing

如果我将这个 link 提取到我的电子邮件中,那么我如何使用 C#.Net 代码找出它的原始名称 "Image.png"?

您提到的URL包含共享文件的file ID。如果您有权访问该文件,则可以通过使用 drive 获取文件的元数据来检索 文件名又名 title api.

文件 ID:1xYe18oaj2kpF6S--Vn_iJgdpKifTPvpkniZkV1-fpFc

试试下面的代码。希望您了解身份验证过程。如果看不到下面的链接。

public static void printFile(DriveService service) {
    try {

      String fileId = "1xYe18oaj2kpF6S--Vn_iJgdpKifTPvpkniZkV1-fpFc";
      File file = service.Files.Get(fileId).Execute();
      Console.WriteLine("Title: " + file.Title);

    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

检查此处给出的 .NET 示例: https://developers.google.com/drive/v2/reference/files/get