为"googleapis.com/auth/userinfo"启用谷歌API



我正在开发Google Chrome扩展名。我希望能够使用来自这些端点的数据访问用户配置文件信息:

https://www.googleapis.com/auth/userinfo

https://www.googleapis.com/oauth2/v1/userinfo

我似乎无法访问这些资源。从我的网络搜索中,看来我可能需要在Google开发人员控制台中启用库API。但是我看着那里,找不到适当的API来启用。有人知道我应该启用哪个API?

您至少需要如前所述添加范围https://www.googleapis.com/auth/userinfo.profile

然后您可以使用oauth2 API,就像如何使用sheetscalendar等。

在nodejs中,这是这样的:

    const { google } = require('googleapis')
    const auth = new google.auth.OAuth2(
      keys.web.client_id,
      keys.web.client_secret,
      keys.web.redirect_uris[0]
    )
    // get the tokens from google
    auth.credentials = tokens
    const oauth2 = google.oauth2({ version: 'v2', auth })
    const userinfo = await oauth2.userinfo.get()
    console.log(userinfo)

此处记录了API:https://googleapis.dev/nodejs/googleapis/latest/oauth2/interfaces/schemaqureinfo.html#info。那里的源代码也有一些示例。

如果您只需要用户的aft for Auth等。D People API在Google Cloud API文档中无处不在。

另外,您需要提及范围https://www.googleapis.com/auth/userinfo.email不是 https://www.googleapis.com/auth/userinfo.profile One。

P.S。这是一个古老的问题,但没有得到答复。可能,您已经解决了它。我正在为将来的人们或我的未来自我发布。

,如果您从用户有访问令牌,则可以从这些端点检索数据。首先,您必须通过使用 Google登录API 允许用户登录来获得访问令牌。然后从以下链接中检索数据。https://www.googleapis.com/oauth2/v1/userinfo?access_token=put_your_user_user's_access_token_here

最新更新