项目中尚未使用旧版 People API

2024-01-09

我在调用 google 登录 API 时遇到错误。错误是

“旧版 People API 之前未在项目 ************ 中使用过或已被禁用”

但人员 API 已启用。如何解决这个错误?

这是我的 google api url 这足以解决我的问题

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';
            }
        }
    }

这是我的代码,其中我使用应用程序密钥作为谷歌密钥,现在访问令牌向我解释问题出在哪里


这里的技巧是它说legacy people api,这通常意味着您正在尝试使用旧的之一Google+ https://support.google.com/googlecurrents/answer/9217723?hl=en scopes.

许多与个人资料相关的端点曾经是 google+ api 的一部分被移动到人员API https://developers.google.com/people/api/rest关闭后Google+ https://support.google.com/googlecurrents/answer/9217723?hl=en .

正如您所调用的端点所看到的,您正在尝试使用几年前关闭的旧 google+ 端点。

googleapis.com/plus/v1

你应该使用people.get https://developers.google.com/people/api/rest/v1/people/get

正确的终点是。

GET https://people.googleapis.com/v1/{resourceName=people/*}

人员 API 范围

这些是新的范围人员API https://developers.google.com/people/api/rest.

启用人员 API

您需要做的第一件事是仔细检查客户端 ID 和您正在使用的项目。其实和你想象的一样。

然后去谷歌云控制台 https://console.cloud.google.com/apis/dashboard对于那个项目。点击库

在搜索框中搜索人员

并选择人员 api

然后点击启用

一旦它在与您正在使用的客户端 ID 相同的项目中启用,它应该会在几分钟内起作用。

PHP code

假设您正在遵循PHP 快速入门 https://developers.google.com/people/quickstart/php类似下面的内容应该会给您带来您正在寻找的响应。

 $results = $service->people->get('people/me');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

项目中尚未使用旧版 People API 的相关文章

随机推荐