1
我在网络客户端使用Google picker来允许用户授权我的应用程序并选择要下载的文件。我检索选定文件的fileId和oauthToken,并将其传递到我的后端,类似于我在此处找到的(Google picker and backend file download)。Google Picker客户端与服务器.Net文件下载403禁止
后端进程是.Net,我使用下面显示的代码提交文件请求。但是,即使相同的Get请求在Postman中正常工作,但通过相同的Url,FileId和oAuthToken信息发送时,我也会收到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;
}
403通常意味着许可。答复的主体应该有更多的信息。 – pinoyyid
您是否尝试使用[webContentLink](https://developers.google.com/drive/v3/web/manage-downloads)下载文件?我可以使用它从我的云端硬盘下载文件。 – noogui
响应主体没有包含任何其他信息。我尝试将auth/drive.readonly的作用域权限增加到auth/drive,但没有任何效果。在google.picker文档中,我无法找到webContentLink属性。最近的属性是downloadUrl,但是该属性在传递回回调函数的google.picker文档中未定义。 –