我正在开发 Google Chrome 扩展程序。我希望能够使用来自这些端点的数据访问用户个人资料信息:
我似乎无法访问这些资源。从我的网络搜索来看,我可能需要在 Google Developers Console 中启用一个库 API。但我在那里看了看,找不到合适的 API 来启用。有谁知道我应该启用哪个 API?
最佳答案
您至少需要按照上述添加范围 https://www.googleapis.com/auth/userinfo.profile
。
然后您可以像使用sheets
、calendar
等一样使用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/