google-chrome-extension - 为 "googleapis.com/auth/userinfo"启用 Google API

标签 google-chrome-extension google-api google-oauth google-developers-console

我正在开发 Google Chrome 扩展程序。我希望能够使用来自这些端点的数据访问用户个人资料信息:

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

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

我似乎无法访问这些资源。从我的网络搜索来看,我可能需要在 Google Developers Console 中启用一个库 API。但我在那里看了看,找不到合适的 API 来启用。有谁知道我应该启用哪个 API?

最佳答案

您至少需要按照上述添加范围 https://www.googleapis.com/auth/userinfo.profile

然后您可以像使用sheetscalendar 等一样使用oauth2 api。

在 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/Schema$Userinfo.html#info .那里的源代码中也有一些示例。

关于google-chrome-extension - 为 "googleapis.com/auth/userinfo"启用 Google API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48632883/

相关文章:

python - 适用于 Python 的 Google 云端硬盘 API : how to create credential?

javascript - 在我的 chrome 扩展的其他选项卡中注入(inject)脚本时出错

javascript - Google Drive SDK/API gapi 无法在 IIS 服务器上加载身份验证(Javascript)

c# - IdentityServer4 - 缺少来自 Google 的声明

javascript - 谷歌javascript登录api : no offline access

python - Google_api 凭据错误来自 CMD 或 .bat 文件执行,但不是来自 IDE

asp.net-mvc - MVC 谷歌登录 - OpenID 身份验证请求包含未注册的域

javascript - 将JS代码注入(inject)网站的所有页面

javascript - 使用javascript获取远程url最后修改日期

javascript - Chrome 扩展 XSS 可能性