【发布时间】:2012-12-06 11:21:17
【问题描述】:
我正在尝试使用提供的 .NET SDK 在 google 中进行授权,但由于“凭据无效”错误而失败。我找到了这个答案
Google Calendar V3 2 Legged authentication fails
但我仍然没有看到错误在哪里。看起来一切都按照描述完成了。
这是我的代码
const string CONSUMER_KEY = "mytestdomain.com";
const string CONSUMER_SECRET = "my_consumer_secret";
const string TARGET_USER = "user";
const string SERVICE_KEY = "some_api_key";
var auth = new OAuth2LeggedAuthenticator(CONSUMER_KEY, CONSUMER_SECRET, TARGET_USER, CONSUMER_KEY);
var service = new DriveService(auth) { Key = SERVICE_KEY };
var results = service.Files.List().Fetch();
Console.WriteLine(results.Items.Count);
这里是谷歌控制面板的截图。我刚刚替换了domain name、consumer key 和api key。
来自Manage API client access页面的截图
来自Manage OAuth key and secret for this domain页面的截图
屏幕截图来自API AccessGoogle API console中的页面
【问题讨论】:
-
我假设您已经看过这个问题:stackoverflow.com/questions/11556875/…,当然还有developers.google.com/drive
-
我不明白你的意思。第一个链接说明在哪里下载 DLL,第二个链接包含一些示例和文档。我不是问在哪里下载它,它已经下载,添加为项目的参考并且它可以工作。我只是无法授权,因为它给了我“Invalid Credentials”错误。
-
我问的原因是因为 Google Drive API 与您提到的问题所使用的 Google Calendar API 不同。当您点击“允许访问所有 API”时会发生什么?
-
没什么。我得到同样的错误。
标签: c# .net oauth-2.0 google-drive-api