9

我想获取从我的应用登录的用户的所有谷歌私人连接。 我已启用Google人员和Google Plus API。我设置了证书API密钥,客户端密码为&。与我试图获取用户的连接的URL是使用谷歌人访问谷歌连接API

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

另外,我使用的库护照谷歌-的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: '/' 
    })); 

回答

2

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

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

我已测试过您发送的请求,但它确实有效,但此请求要求您至少已通过connections scopes中的一个验证。

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

如果你还没有,那么你会得到一个无法访问的错误消息。

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

好的。我有API关键的东西。但是,通过access_token,我得到以下错误:**请求缺少必需的身份验证凭据。期望的OAuth 2访问令牌谷歌人api **。我正在使用google-passport-oauth软件包来获取用户令牌和google-api-nodejs-client来访问Google的人员API –

+0

@ParthVyas如果您有访问令牌,请尝试使用它作为请求的标题(也许'授权:“持证人”+ accessToken') – BNK

+1

@BNK你不需要通过加上&access_token =做到这一点,在请求结束时,你正在做同样的事情。 – DaImTo