简体   繁体   English

Google People API (howto auth with API Key)

[英]Google People API (howto auth with API Key)

can someone please explain to me how the Google People API works.有人可以向我解释一下 Google People API 是如何工作的吗?

I would like to create a CronJob which automatically creates contacts from a given dataset.我想创建一个 CronJob,它会自动从给定的数据集中创建联系人。 So far no problem BUT unfortunately I can't manage to authenticate myself via API key.到目前为止没问题但不幸的是我无法通过 API 密钥对自己进行身份验证。

This message is always displayed when I try to authenticate当我尝试进行身份验证时始终显示此消息
Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

Here is a description how it should work: https://developers.google.com/people/v1/how-tos/authorizing这是它应该如何工作的描述: https://developers.google.com/people/v1/how-tos/authorizing

Here you can try out the method (unfortunately it never works here either): https://developers.google.com/people/api/rest/v1/people/createContact在这里你可以试试这个方法(不幸的是它在这里也不起作用): https://developers.google.com/people/api/rest/v1/people/createContact

Sidenode: i use PHP:) Sidenode:我使用 PHP :)

Issue:问题:

You are trying to add a contact for a person.您正在尝试为某人添加联系人。 This is a request for an individual's private data, and accessing it requires authorization:这是对个人隐私数据的请求,访问它需要授权:

If the request requires authorization (such as a request for an individual's private data), then the application must provide an OAuth 2.0 token with the request.如果请求需要授权(例如请求个人的私人数据),则应用程序必须在请求中提供 OAuth 2.0 令牌。

API keys can only be used to access public data. API 密钥只能用于访问公共数据。 In this case, you need to authenticate via OAuth 2.0.在这种情况下,您需要通过 OAuth 2.0 进行身份验证。 There's simply no way around it.根本没有办法解决它。

Solution:解决方案:

Take a look at the following example, which shows how to go through the OAuth process: PHP Quickstart .看看下面的例子,它展示了如何通过 OAuth 过程 go: PHP 快速入门

Avoiding user interaction:避免用户交互:

Since, in this case, you would like to avoid user interaction, your only option would be to use a service account that has been granted domain-wide authority .因为在这种情况下,您希望避免用户交互,所以您唯一的选择是使用已被授予全域权限的服务帐户。 This can be used to act on behalf of any user in a domain, without this user providing explicit authorization.这可以用于代表域中的任何用户,而无需该用户提供明确的授权。

Because of this, you need to be a G Suite domain administrator in order to use that, and all users for whom this application should execute should be part of this domain.因此,您需要成为 G Suite 域管理员才能使用它,并且该应用程序应为其执行的所有用户都应该是该域的一部分。

If that's not the case (if you don't have domain, or not all users belong to this domain), user interaction is required in order to access individual data using People API. That's because users have to authorize the application to access data on their behalf.如果不是这种情况(如果您没有域,或者并非所有用户都属于该域),则需要用户交互才能使用 People API 访问个人数据。这是因为用户必须授权应用程序访问数据他们的代表。

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM