【问题标题】:Google People API gapi.client.people.people.connections.list returns Request had insufficient authentication scopesGoogle People API gapi.client.people.people.connections.list 返回请求的身份验证范围不足
【发布时间】:2018-02-25 11:46:50
【问题描述】:

Google People API gapi.client.people.people.connections.list 返回错误 403 并带有错误消息 请求的身份验证范围不足,即使初始化包括所需的范围

   gapi.client.init({
            apiKey: '***masked***',
            discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"],
            clientId: "***masked***.apps.googleusercontent.com",
            'scope': "https://www.googleapis.com/auth/contacts.readonly"
        });

请求看起来像这样

api.client.people.people.connections.list({
        'resourceName': 'people/me',
        'personFields': 'names,emailAddresses'
    }).then(function (response) {
        console.log(response.result.emailAddresses[0].value);
        if (importGmailCallback) {
            importGmailCallback(response);
        }
    }, function (reason) {
        console.log('Error: ' + reason.result.error.message);
    });

在此处等待登录更改

Promise.resolve(window.gapi.auth2.getAuthInstance().signIn()).then(function () {
        // Listen for sign-in state changes.
        gapi.auth2.getAuthInstance().isSignedIn.listen(googlePeopleSignedInCallback);
        // Handle the initial sign-in state.
        googlePeopleSignedInCallback(gapi.auth2.getAuthInstance().isSignedIn.get());
    }, function (error) {
        console.log(error);
    });

我在 API Explorer 中成功使用了类似的值,尝试删除访问并重新进行身份验证,删除了所有 cookie,但没有成功

【问题讨论】:

  • 您是否确保在发出请求之前等待 init() 响应(这是一个承诺)?示例:developers.google.com/api-client-library/javascript/start/…
  • 是的,Promise.resolve(window.gapi.auth2.getAuthInstance().signIn()).then(function () { // 监听登录状态变化。gapi.auth2.getAuthInstance ().isSignedIn.listen(googlePeopleSignedInCallback); // 处理初始登录状态 googlePeopleSignedInCallback(gapi.auth2.getAuthInstance().isSignedIn.get()); }, function (error) { console.log(error) ; });
  • 您的应用程序在登录时要求的权限是什么?
  • 我的意思是在提示用户允许访问各种谷歌服务的同意屏幕上。通常,此屏幕会在您登录后出现。

标签: javascript google-api google-oauth google-people-api


【解决方案1】:

尝试删除范围内的引号。

替换:

'范围':"https://www.googleapis.com/auth/contacts.readonly"

范围:“https://www.googleapis.com/auth/contacts.readonly

【讨论】:

  • 很遗憾,这不起作用,看来我必须使用旧 API
  • 无论你的船是什么;)
【解决方案2】:

也尝试添加此范围: "https://www.google.com/m8/feeds"

【讨论】:

  • 虽然理论上这可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
  • 没用,我希望你能贡献一些你尝试过或知道的东西
猜你喜欢
  • 2021-11-22
  • 1970-01-01
  • 2016-06-21
  • 1970-01-01
  • 2016-04-28
  • 1970-01-01
  • 2021-12-12
  • 2023-03-13
  • 2021-10-20
相关资源
最近更新 更多