这是一个全新的项目,也是我第一次尝试使用Google Drive的API。我立即得到一个401,当我运行:Google Drive API在尝试验证时返回401
static void Main(string[] args)
{
UserCredential credential;
using (var filestream = new FileStream("client_secrets.json",
FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(filestream).Secrets,
new[] { DriveService.Scope.Drive },
"user",
CancellationToken.None,
new FileDataStore("DriveCommandLineSample")).Result;
}
此代码是从https://developers.google.com/drive/web/quickstart/quickstart-cs逐字复制。我下载了JSON文件client_secrets.json,并验证GoogleClientSecrets.Load(filestream).Secrets与我在Credentials页面上看到的值相同。
我已经用Firefox和IE测试过。我究竟做错了什么?
我正在使用Drive API。我已经不得不做所有这些事情来生成JSON文件。 – saltface
好的,你正在运行的代码是一个Web应用程序,不是吗? 因为您需要为浏览器创建一个密钥,另一个用于安卓应用。你用的是正确的吗? – paulofer85
是的。我选择了_installed application_和_other_。我的凭证位于本机应用程序的_Client ID标题下。 – saltface