Google表格Api请求的身份验证范围不足 [英] Google Sheets Api Request had insufficient authentication scopes
本文介绍了Google表格Api请求的身份验证范围不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static string[] Scopes = { SheetsService.Scope.Spreadsheets };
static string ApplicationName = "Google Sheets API .NET Quickstart";
public String spreadsheetId;
SheetsService service;
public GoogleHandler(String id)
{
spreadsheetId = id;
UserCredential credential;
using (var stream =
new FileStream(@"bin\client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
}
这是我的Google Sheets API代码.我有static string[] Scopes = { SheetsService.Scope.Spreadsheets };
,这是我为该问题找到的解决方案,但是并没有解决我的问题.我已经删除了.credentials文件夹,它没有提示我登录.
This is my code for Google Sheets API. I have the static string[] Scopes = { SheetsService.Scope.Spreadsheets };
which were solutions I found for this problem, however that did not fix my problem. I have already deleted my .credentials folder and it does not prompt me to login.
推荐答案
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None
//new FileDataStore(credPath, true)
).Result;
我注释掉了这一行,并修复了所有问题!
I commented out that line and it fixed everything!
这篇关于Google表格Api请求的身份验证范围不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文