Legacy People API 尚未在项目中使用 [英] Legacy People API has not been used in project
问题描述
我在调用谷歌登录 API 时出错.错误是
<块引用>Legacy People API 之前未在项目 ************ 中使用或已禁用"
但是人们 API 是启用的.如何解决这个错误?
这是我的 google api url 是否足以解决我的问题
if (empty($_POST['google_key'])) {$error_code = 5;$error_message = 'google_key (POST) 丢失';} 别的 {$app_key = $_POST['google_key'];//https://www.googleapis.com/plus/v1/people/me?access_token={$access_token}&key={$app_key}$get_user_details = fetchDataFromURL("https://people.googleapis.com/v1/people/me?access_token={$access_token}&key={$app_key}");$json_data = json_decode($get_user_details);if (!empty($json_data->error)) {$error_code = 4;$error_message = $json_data->error;} else if (!empty($json_data->id)) {$social_id = $json_data->id;$social_email = $json_data->emails[0]->value;$social_name = $json_data->displayName;如果(空($social_email)){$social_email = 'go_' .$social_id .'@google.com';}}}
这是我的代码,其中我使用应用程序密钥作为谷歌密钥,访问令牌现在向我解释了问题所在
这里的诀窍是它说legacy people api
,这通常意味着您正在尝试使用旧的
启用人 api
您需要做的第一件事是仔细检查客户端 ID 和您正在使用的项目.实际上和你认为的一样.
然后转到该项目的
在搜索框中搜索人物
并选择人员 api
然后点击启用
在与您使用的客户端 ID 相同的项目中启用它后,它应该会在几分钟内起作用.
PHP 代码
假设您正在关注 PHP 快速入门,以下内容应该会给您您正在寻找的回复.
$results = $service->people->get('people/me');
I am getting error when calling google sign in API. Error is
"Legacy People API has not been used in project ************ before or it is disabled"
But the people API is enable. How to solve this error ?
This is my google api url is this is sufficient to solve my problem
if (empty($_POST['google_key'])) {
$error_code = 5;
$error_message = 'google_key (POST) is missing';
} else {
$app_key = $_POST['google_key'];
// https://www.googleapis.com/plus/v1/people/me?access_token={$access_token}&key={$app_key}
$get_user_details = fetchDataFromURL("https://people.googleapis.com/v1/people/me?access_token={$access_token}&key={$app_key}");
$json_data = json_decode($get_user_details);
if (!empty($json_data->error)) {
$error_code = 4;
$error_message = $json_data->error;
} else if (!empty($json_data->id)) {
$social_id = $json_data->id;
$social_email = $json_data->emails[0]->value;
$social_name = $json_data->displayName;
if (empty($social_email)) {
$social_email = 'go_' . $social_id . '@google.com';
}
}
}
this is my code where m using app key as google key and the access token now explain me where's the problem
The trick here is that it says legacy people api
, this often means you are trying to use one of the old Google+ scopes.
A lot of the profile related endpoints that where once part of the google+ api were moved to the People api after the shutdown of Google+ .
As you can see by the endpoint you are calling you are trying to use the old google+ endpoint which was shutdown years ago.
googleapis.com/plus/v1
You should be using people.get
The correct endpoint would be.
GET https://people.googleapis.com/v1/{resourceName=people/*}
People API scopes
These are the new scopes for the people api.
Enable people api
The first thing you need to do is double check the Client id and the project you are using. Are in fact the same as the one you think it is.
Then go to Google cloud console for that project. Click library
In the search box search for people
And select people api
Then click enable
Once it has been enable in the same project as the client id you are using it should work within a few minutes.
PHP code
Assuming you are following the PHP quick start something like the following should give you the response you are looking for.
$results = $service->people->get('people/me');
这篇关于Legacy People API 尚未在项目中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!