尝试通过 C# 中的 REST 从 Google Drive 检索配额信息。这是一个代码片段:
public async Task<string> HasQuota(string accessToken) {
var url = string.Concat(new string[] {
" https://www.googleapis.com/drive/v2/about",
"?access_token=" + accessToken,
"&fields=quotaBytesTotal%2CquotaBytesUsed"
});
// Create the request.
var request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
// Create the response.
var response = await Task<WebResponse>.Factory.FromAsync(
request.BeginGetResponse,
request.EndGetResponse,
request
);
if (((HttpWebResponse)response).StatusDescription == "OK") {
using (Stream stream = response.GetResponseStream()) {
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
return reader.ReadToEnd();
}
}
return null;
}
当我获得 access_token 时,我使用https://www.googleapis.com/auth/drive.file限定了身份验证请求,并且我的测试用户授予了权限。据我所知,我有执行此调用的代码要求。
但是,当我尝试执行此方法时出现 NotFound 异常。文档说我可以在查询字符串中传递 access_token 或将 Authorization 标头添加到请求中,即
request.Headers["Authorization"] = string.Format("Bearer {0}", accessToken);
任何想法为什么我可能会得到这个例外?
谢谢