从服务器上的Google Drive下载文件 [英] Download file from google drive on server
问题描述
我使用JavaScript选择器从我的Google驱动器中获取文件,它工作正常,然后从驱动器中下载url和acces_token 我想从我的服务器上从该文件下载字节数组,然后将URL和acces_token指向它(使用ajax),没问题
I use an javascript picker to get file from my google drive, it's work well and i get then download url and acces_token from my drive I would like to download bytes array from this file from my server, then i path the url and acces_token to it (with ajax), no problem
在服务器上,我将使用此代码获取数据(工作正常!!!)
on server i would get data with this code (it's worked !!!)
public void DownloadFile(string url, string AccessToken)
{
try
{
byte[] BB;
using (WebClient wc = new WebClient())
{
wc.Headers.Add("Authorization", "Bearer " + AccessToken);
BB = wc.DownloadData(url);
}
}
catch (Exception ex)
{
throw ex;
}
}
现在我收到403错误??
now i get an 403 error ??
url类似于" https://content. googleapis.com/drive/v2/files.....?key=mykey ....."
url are like "https://content.googleapis.com/drive/v2/files.....?key=mykey....."
Google服务器上发生了什么变化?
what's changed on google server ?
谢谢
推荐答案
如果要使用Drive API下载文件并在标头中设置访问令牌,则必须通过调用以下网址来做到这一点:
If you want to download a file using the Drive API and setting the access token in the header, you have to do it by calling this url:
https://www. googleapis.com/drive/v2/files/[file-Id]?alt=media
如响应部分所述在文件:获取端点中.为了使其正常工作,url参数alt=media
确实很重要.不要使用API密钥.
As it's told in the Response section in the Files: get endpoint. It's really important the url parameter alt=media
in order to make it work. Don't use an API Key.
这篇关于从服务器上的Google Drive下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!