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