I have code that uploads files to Google Drive and sets the appropriate permissions so that anyone in the domain can read them.
If I use the Google Drive API explorer and enter the Id of the file and enter "webViewLink" in the "fields" textbox, then when I execute the request, I see something like this (actual link obfuscated)...
{
"webViewLink": "https://drive.google.com/file/d/abcdef123456/view?usp=drivesdk"
}
Entering the link in a private browser window allows me to see the file as expected.
However, if I try to get the link in my C# code...
FilesResource.GetRequest request = _service.Files.Get(fileId);
request.Fields = "webViewLink";
var file = await _service.Files.Get(fileId).ExecuteAsync();
...then the file.WebViewLink
property is always blank. Looking at the network tab, it seems is if the same API is being called with the same parameters,
Anyone any ideas? I have double-checked, and I'm using the same Google account in both the API explorer and my code (I know this because otherwise I wouldn't be able to see other files in the drive)
CodePudding user response:
Your C# code sets up a request and sets the Fields
on it but then you call the _service.Files.Get(fileId)
again so you're ignoring the original request you set up with the additional Fields
, therefore it is using the default Fields
and not the ones you set up.
Try doing var file = await request.Get(fileId).ExecuteAsync();
so it'll use the Fields
set up for that requset.