2

I have an mp4 video file that sits in the "Videos" folder in Google Drive. I want to get a shareable link to this file using C# sdk v3. In my code I set permissions for the file (and the folder):

string fileId = "..real..file..id..here.."
Google.Apis.Drive.v3.Data.Permission permission = new Google.Apis.Drive.v3.Data.Permission();
permission.Type = "anyone";
permission.Role = "reader";
permission.AllowFileDiscovery = true;

PermissionsResource.CreateRequest request = _service.Permissions.Create(permission, fileId);
request.Fields = "id";
request.Execute();

_service variable is a DriveService object. I can see that permissions are set correctly for the file (and for the folder). Then I try to get the link with the following code:

 FilesResource.ListRequest listRequest = _service.Files.List();
 List<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files.ToList();
 Google.Apis.Drive.v3.Data.File myVideo = files.Single(f => f.Id == fileId);
 string shareableLink = myVideo.WebContentLink;

File "myVideo" is retrieved correctly, however, the WebContentLink property is null. What am I missing here?

Update: AllowFileDiscovery = false; doesn't make any difference.

Update: After permissions are set you can construct the url manually with the file id: https://drive.google.com/uc?id=..file..id..goes..here

Alxg
  • 293
  • 3
  • 14
  • Have you tried reading this? it discuss how to retrieve WebContentLink: http://stackoverflow.com/questions/13517409/get-webcontentlink-from-google-drive-api-with-converted-document / http://stackoverflow.com/questions/13933790/unable-to-retrieve-file-content-from-google-drive-api – Android Enthusiast May 17 '16 at 11:09

1 Answers1

1

This is very old question with no answer. I faced similar dilemma i.e. webcontentlink in result was coming as NULL. The solution is that you need to put "webContentLink" in request's fields property as shown below.

listRequest.Fields = "id, webContentLink";
Risky Pathak
  • 598
  • 5
  • 16