【问题标题】:Access google connections using google people API使用 google people API 访问 google 连接
【发布时间】:2017-07-24 01:16:45
【问题描述】:

我想获取从我的应用登录的用户的所有 google 私人连接。 我启用了 Google People 和 Google Plus API。我设置了凭据 API 密钥、客户端 ID 和客户端密码。我试图获取用户连接的 url 是

https://people.googleapis.com/v1/people/me/connections?fields=connections&key=api_key&access_token=access_token

另外,我正在使用库 passport-google-oauth 来获取用户 access_token。我在上面的 URL 中有什么遗漏的吗?

我的谷歌验证码是

    // send to google to do the authentication
    // profile gets us their basic information including their name
    // email gets their emails
    app.get('/auth/google', passport.authenticate('google', {
        scope: ['profile', 'email','https://www.googleapis.com/auth/contacts.readonly', 'https://www.googleapis.com/auth/contacts']
    }));

    // the callback after google has authenticated the user
    app.get('/auth/google/callback',
    passport.authenticate('google', {
        successRedirect: '/profile',
        failureRedirect: '/'
    }));

【问题讨论】:

    标签: google-api google-api-nodejs-client google-people-api passport-google-oauth


    【解决方案1】:

    您没有提到您遇到了什么错误,但通过查看您使用的网址,我可以告诉您一些事情。

    people.connections.list 访问私人用户数据。因此,您不需要添加仅用于访问公共数据的密钥。但是,两者都不会导致任何错误消息。

    我已经测试了您发送的请求,它确实有效,但是此请求要求您至少通过connections scopes 之一进行身份验证。

    https://www.googleapis.com/auth/contacts 请求您的应用程序 授予对已验证联系人的读写访问权限 用户的 Google 通讯录。 https://www.googleapis.com/auth/contacts.readonly 请求您的 应用程序被授予对经过身份验证的用户的联系人的读取访问权限 Google 通讯录。

    如果您没有,那么您将收到一条无法访问的错误消息。

    {
      "error": {
        "code": 403,
        "message": "Request had insufficient authentication scopes.",
        "status": "PERMISSION_DENIED"
      }
    }
    

    【讨论】:

    • 好的。我得到了 API 密钥的东西。但是使用我通过的 access_token,我收到以下错误:Request is missing required authentication credential。预期的 OAuth 2 访问令牌 google people api。我正在使用包 google-passport-oauth 来获取用户令牌和 google-api-nodejs-client 来访问 google 的人员 API
    • @ParthVyas 如果您有访问令牌,请尝试将其用作请求的标头(可能是Authorization: "Bearer " + accessToken
    • @BNK 您不需要通过在请求结束时添加 &access_token= 来执行此操作,您正在做同样的事情。
    • @ParthVyas 请发布您的身份验证代码我认为您的访问令牌生成有问题
    • @DaImTo 我已经用授权码更新了问题,请看一下!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    相关资源
    最近更新 更多