尝试通过C#中的REST从Google云端硬盘检索配额信息。这是一段代码:
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);
为什么我可能会遇到此例外的任何想法?
由于
答案 0 :(得分:0)
我没有在控制台中启用Drive API选项...