0

I am hosting my website on IIS, and using service account to upload and request drive files. I am able to get the webViewLink but because its a service account, it doesn't show me a file on this link but permission issue that service account should grant the permission enter image description here.

On using code to grant permission for a particular user, then in that user's drive, I am able to see the file. But my question is how can I view file on browser (based on my scenario above) using System.Diagnostics.Process.Start(newFile.webViewLink)

Here is my code for upload and getting the file:

{   File fileInGoogleDrive = Utils.uploadToDrive(service, pathOfTheFileToBeUploaded, "root");

                File metadata = Utils.GetFileRequestedMetadata(service, fileInGoogleDrive.Id);

                Permission toShare = new Permission();
                toShare.EmailAddress = "xyz@gmail.com";
                toShare.Type = "user";
                toShare.Role = "reader";

                PermissionsResource.CreateRequest createRequest = service.Permissions.Create(toShare, metadata.Id);
                createRequest.Execute();

                return metadata.WebViewLink;
}
public static File uploadToDrive(DriveService _service, string _uploadFile, string _parent = "root")
        {

            if (!String.IsNullOrEmpty(_uploadFile))
            {
                //string mimeType = GetMimeType(_uploadFile); // We can have mime type passed in request
                File fileMetadata = new File();
                fileMetadata.Name = System.IO.Path.GetFileName(_uploadFile);
                fileMetadata.MimeType = GetMimeType(_uploadFile);


                    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;

}
Atihska
  • 4,803
  • 10
  • 56
  • 98
  • I am still stuck at this problem. Could anyone please provide some hints? – Atihska Mar 03 '16 at 22:09
  • Looks like is a duplicate of http://stackoverflow.com/questions/35711489/using-google-drive-v3-api-and-service-account-auth-webviewlink-is-null. If this is different, can you provide the HTTP full request/response and what is expected. – Andres Mar 04 '16 at 18:58

0 Answers0