从服务器上的 google 驱动器下载文件
Download file from google drive on server
我使用 javascript 选择器从我的 google 驱动器获取文件,它运行良好,然后我从我的驱动器下载 url 和 acces_token
我想从我的服务器下载这个文件的字节数组,然后我将 url 和 acces_token 指向它(使用 ajax),没问题
在服务器上,我将使用此代码获取数据(有效!!!)
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 错误 ??
url 就像“https://content.googleapis.com/drive/v2/files.....?key=mykey.....”
google 服务器发生了什么变化?
谢谢
如果您想使用驱动器 API 下载文件并在 header 中设置访问令牌,您必须调用此 url:
https://www.googleapis.com/drive/v2/files/[file-Id]?alt=media
如 Response section in the Files: get 端点所述。 url 参数 alt=media
非常重要,这样才能使其正常工作。不要使用 API 键。
我使用 javascript 选择器从我的 google 驱动器获取文件,它运行良好,然后我从我的驱动器下载 url 和 acces_token 我想从我的服务器下载这个文件的字节数组,然后我将 url 和 acces_token 指向它(使用 ajax),没问题
在服务器上,我将使用此代码获取数据(有效!!!)
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 错误 ??
url 就像“https://content.googleapis.com/drive/v2/files.....?key=mykey.....”
google 服务器发生了什么变化?
谢谢
如果您想使用驱动器 API 下载文件并在 header 中设置访问令牌,您必须调用此 url:
https://www.googleapis.com/drive/v2/files/[file-Id]?alt=media
如 Response section in the Files: get 端点所述。 url 参数 alt=media
非常重要,这样才能使其正常工作。不要使用 API 键。