我怎么能知道原始文件名从谷歌驱动器链接使用c#代码



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

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

如果我提取这个链接嵌入在我的电子邮件,那么我怎么能找出它的原始名称"Image.png"使用c#。Net代码?

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

文件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

最新更新