Google Picker Client with Server .Net File Download 403 Forbidden

Google Picker Client with Server .Net File Download 403 Forbidden

我在 Web 客户端中使用 Google 选择器以允许用户授权我的应用程序和 select 一个文件供下载。我检索 selected 文件的 fileId 和 oauthToken 并将其传递到我的后端,类似于我在此处找到的内容 (Google picker and backend file download)。

后端进程是.Net,我正在使用下面显示的代码提交文件请求。但是,当我发送相同的 Url、FileId 和 oAuthToken 信息时,即使相同的 Get 请求在 Postman 中工作正常,我也会收到 403 Forbidden 错误。

关于我的 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;
}

我能够使用 Google Drive REST API 的第 2 版解决问题:

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

文档表明这也适用于版本 3 (https://developers.google.com/drive/v3/web/manage-downloads),但不适用于我的情况。