1
我正在使用谷歌驱动器v3 api上传文件,然后在浏览器中使用Web浏览器在响应中预览链接。但是,网络视图链接将变为空。当我使用v2时,我可以使用备用链接进行操作。使用Google Drive V3 API和服务帐户验证,WebViewLink为空
我还没有设置父文件,所以我假设根据文档,该文件存储在我的驱动器文件夹(根)的服务帐户。由于我无法登录到服务帐户,所以我将该文件与我现有的测试Gmail帐户共享,并将其共享。
我的问题是我怎么能打开使用System.Diagnostics.Process.Start(newFile.WebViewLink);
这里在浏览器中的文件是我的代码:
{
File fileInGoogleDrive = Utils.uploadToDrive(service, pathOfTheFileToBeUploaded, "root");
Permission toShare = new Permission();
toShare.EmailAddress = "[email protected]";
toShare.Type = "user";
toShare.Role = "reader";
PermissionsResource.CreateRequest createRequest = service.Permissions.Create(toShare, fileInGoogleDrive.Id);
createRequest.Execute();
return fileInGoogleDrive.WebViewLink; //THIS IS NULL
}
这里是上传代码:
public static File uploadToDrive(DriveService _service, string _uploadFile, string _parent = "root")
{
if (!String.IsNullOrEmpty(_uploadFile))
{
File fileMetadata = new File();
fileMetadata.Name = System.IO.Path.GetFileName(_uploadFile);
fileMetadata.MimeType = GetMimeType(_uploadFile);
//fileMetadata.Parents = new List<FilesResource>() { new FilesResource() {}};
try
{
byte[] byteArray = System.IO.File.ReadAllBytes(_uploadFile);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FilesResource.CreateMediaUpload request = _service.Files.Create(fileMetadata, stream, GetMimeType(_uploadFile));
request.Upload();
return request.ResponseBody;
}
catch (System.IO.IOException iox)
{
// Log
return null;
}
catch (Exception e) // any special google drive exceptions??
{
//Log
return null;
}
}
else
{
//Log file does not exist
return null;
}
}
任何人都可以请指导我在这?
http://stackoverflow.com/questions/35317660/google-drive-api-ver3-how-share-on-my的可能重复-web-page – abielita
谢谢@abielita – Atihska