英文:
Do I must have "Google Workspace" account to enable "Google Keep API"?
问题
I keep running into "invalid scope" error while enabling "Google Keep API."
I've tried other APIs like "Google Drive API" with the same code, and it worked, but failed for Google Keep. I searched on the Internet; it seems that I need to have a "Google Workspace" account to enable it. Is that true?
I use .NET Core 3.1 MVC to implement OAuth 2.0 authentication, but it failed for Google Keep.
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using test_coremvc.Models;
using Google.Apis.Auth.AspNetCore3;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
using Google.Apis.Keep.v1;
namespace test_coremvc.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
[GoogleScopedAuthorize(KeepService.ScopeConstants.Keep)]
public async Task<IActionResult> KeepFileList([FromServices] IGoogleAuthProvider auth)
{
GoogleCredential cred = await auth.GetCredentialAsync();
var service = new KeepService(new BaseClientService.Initializer
{
HttpClientInitializer = cred
});
//var files = await service.Files.List().ExecuteAsync();
//var fileNames = files.Files.Select(x => x.Name).ToList();
return View();
}
}
}
英文:
I keep running into "invalid scope" error while enabling "Google Keep API"
I've tried other APIs like "Google drive API" with same code and it worked,but fail for google keep.
I search on Internet,it seems that I need to have "Google Workspace"account to enable it,is that true?
I use .netcore3.1 mvc to implement the Oauth2.0 authentication but it failed for Google Keep....
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using test_coremvc.Models;
using Google.Apis.Auth.AspNetCore3;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
using Google.Apis.Keep.v1;
namespace test_coremvc.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
[GoogleScopedAuthorize(KeepService.ScopeConstants.Keep)]
public async Task<IActionResult> KeepFileList([FromServices] IGoogleAuthProvider auth)
{
GoogleCredential cred = await auth.GetCredentialAsync();
var service = new KeepService(new BaseClientService.Initializer
{
HttpClientInitializer = cred
});
//var files = await service.Files.List().ExecuteAsync();
//var fileNames = files.Files.Select(x => x.Name).ToList();
return View();
}
}
}
答案1
得分: 1
Google Keep API 是仅供企业使用的 API,用于创建和管理您域内的 Keep 笔记,包括解决 CASB 软件识别的问题。
此外,官方文档 显示您需要创建一个服务帐户并授权它。服务帐户是应用程序使用的特殊类型帐户,而不是人员。您可以使用服务帐户代表机器人帐户访问数据或执行操作,或者代表 Google Workspace 或 Cloud Identity 用户访问数据。
因此,它可能只适用于 Google Workspace 域帐户。
我们建议您使用服务帐户方法,但如果您不想创建服务帐户,您可以参考 Gabriel Carballo 的答案 使用经管理员批准的方法(提示:我未验证此方法,仅作为建议)。
英文:
Google Keep API is an enterprise-only API used to create and manage the Keep notes within your domain, including resolving issues identified by CASB software.
In addition, the official documentation shows that you need to create a service account and authorize it. A service account is a special kind of account used by an application, rather than a person. You can use a service account to access data or perform actions by the robot account, or to access data on behalf of Google Workspace or Cloud Identity users.
So, it may only work with Google Workspace domain accounts.
We recommend you use the service account method, but if you don't want to create a service account, you can refer to Gabriel Carballo's answer to use the admin-approved method (tip: I have not verified this method, just as a suggestion).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论