使用google people API访问谷歌连接

Par*_*yas 9 google-api google-api-nodejs-client passport-google-oauth google-people

我想获取从我的应用登录的用户的所有谷歌私人连接.我启用了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
Run Code Online (Sandbox Code Playgroud)

另外,我正在使用图书馆passport-google-oauth来获取用户access_token.以上网址中是否有任何我遗漏的内容.

我的谷歌验证码是

    // 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: '/'
    }));
Run Code Online (Sandbox Code Playgroud)

DaI*_*mTo 2

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

\n\n

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

\n\n

我已经测试了您发送的请求,它确实有效,但是此请求要求您至少通过其中一个连接范围进行身份验证。

\n\n
\n

https://www.googleapis.com/auth/contacts 请求为您的应用授予\n 对经过身份验证的\n 用户\xe2\x80\x99s Google 通讯录中的联系人的读写访问权限。\n https://www .googleapis.com/auth/contacts.readonly请求为您的应用授予对经过身份验证的用户\xe2\x80\x99s\n Google 通讯录中的联系人的读取权限。

\n
\n\n

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

\n\n
{\n  "error": {\n    "code": 403,\n    "message": "Request had insufficient authentication scopes.",\n    "status": "PERMISSION_DENIED"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n