1

I am using Google picker in a web client to allow a user to authorize my application and select a file for download. I retrieve the fileId and oauthToken for the selected file and pass it to my back end similar to what I found here (Google picker and backend file download).

The back-end process is .Net and I am using the code shown below to submit the request for the file. However, I receive a 403 Forbidden error even though the same Get request works fine in Postman when I send though the same Url, FileId, and oAuthToken information.

Any ideas on what might be wrong with the setup of my HttpWebRequest?

public void Download(string pOAuthToken, string pFileId, string pFileName) {
    HttpWebRequest request;
    HttpWebResponse response;

    bool result = false;
    string url = "";

    try {
        url = "https://www.googleapis.com/drive/v3/files/" + pFileId + "?alt=media";
        request = WebRequest.Create(url);
        request.Headers.Add("Authorization", ("Bearer " + pOAuthToken));

        response = request.GetResponse();

        //  Insert code to download file here

        result = true;
    }
    catch (Exception ex) {
        LogError("Download exception.", ex);
    }
    finally {
        response.Close();
    }

    return result;
}
Community
  • 1
  • 1
B Wells
  • 11
  • 3
  • 403 generally means permission. There should be more information in the body of the response. – pinoyyid Jan 24 '17 at 18:31
  • Did you try using the [webContentLink](https://developers.google.com/drive/v3/web/manage-downloads) to download the file? I'm able to download files from my Drive using that. – ReyAnthonyRenacia Jan 25 '17 at 13:14
  • The response body did not contain any other information. I tried increasing the scope permission from auth/drive.readonly to auth/drive but that had no effect. In the google.picker document, I couldn't find a webContentLink property. The closest property was a downloadUrl but this property was undefined in the google.picker document that was passed back to the callback function. – B Wells Jan 25 '17 at 22:33

1 Answers1

0

I was able to resolve the issue by using version 2 of the Google Drive REST API:

url = "https://www.googleapis.com/drive/v2/files/" + pFileId + "?alt=media";

The docs indicate that this should also work with version 3 (https://developers.google.com/drive/v3/web/manage-downloads) but not in my case.

B Wells
  • 11
  • 3