Using Google Drive V3 API and service account auth, WebViewLink is null

后端 未结 1 1129
暗喜
暗喜 2021-01-21 19:46

I am using google drive v3 api to upload a file and then preview it in browser using web view link in the response. But web view link is coming null. When i was using v2, I was

1条回答
  •  滥情空心
    2021-01-21 20:33

    Just wanted to post the syntax in C# for the above. From the google documentation, it says we have to do a get on files and then request using Fields property. "Getting the fields in google drive v3 api for .net"

      File resultFile = null;
      FilesResource.ListRequest listRequest = _service.Files.List();
        /* Specify camelCase format to specify fields. You can also check in debug mode the files properties before requesting which will be null. All properties will be capitalized so make th efirst letter as small(camel case standard)*/
    
      listRequest.Fields = "files(id, webViewLink, size)";                
      var files = listRequest.Execute().Files;
    
    
            if (files != null && files.Count > 0)
            {
                    foreach (var file in files)
                    {
                          if (file.Id == _fileId)
                          {
                               Console.WriteLine("{0}, {1}, {2}", file.Id, file.WebViewLink, file.Size);
                               resultFile = file;
                          }
                     }
             }
    

    0 讨论(0)
提交回复
热议问题