微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Google-People API 已启用,但仍显示无效凭据

如何解决Google-People API 已启用,但仍显示无效凭据

我有一个 Google 的付费开发者帐户。我已验证我的 People API 已启用,并且我使用的是正确的 API 密钥和客户端 ID。当我尝试 Google 登录开始时,我在控制台中收到此错误,原因是 reason.result.error...

{
    code: 401,message: "The request does not have valid authentication credentials.",status: "UNAUTHENTICATED"
}

我验证了 AP​​I 密钥和 ClientID 是正确的。我从这样的登录按钮方法开始......

didClickGoogleLogin = () => {
    // 1. Load the JavaScript client library.
    gapi.load('client',this.googleLoginStart);
}

然后它调用 googleLoginStart 方法...

googleLoginStart = () => {
    
    // 2. Initialize the JavaScript client library.
    gapi.client.init({
        'apiKey': <API KEY HERE>,// clientId and scope are optional if auth is not required.
        'clientId': <CLIENT ID HERE>,'scope': 'profile',}).then(function() {
        // 3. Initialize and make the API request.
        return gapi.client.request({
        'path': 'https://people.googleapis.com/v1/people/me?personFields=Metadata,names,emailAddresses',})
    }).then((response) => {
        console.log(response.result);
        const googleID = response.result.Metadata.sources[0].id;
        const googleEmail = response.result.emailAddresses[0].value;
        this.updateUser(googleID,googleEmail);
    },function(reason) {
        console.log("reason: ",reason);
    });
}

这在我几个月前编写的另一个网络应用程序中对我有用,但现在也不起作用。

知道为什么在启用 API、API 密钥和客户端 ID 正确时我会收到无效凭据错误吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。