【发布时间】:2021-04-03 15:35:15
【问题描述】:
我正在制作一个不需要使用 youtube 帐户信息(显示在频道链接中的 ID)的 chrome 扩展程序。我已经解决了让chrome.identity.getAuthToken 给我一个带有"scopes":["https://www.googleapis.com/auth/youtube.readonly"] 的令牌。它看起来像这样:ya29.a0AfH6SMDRpsZf***48VT_yQ4FCsFc8。现在我有一个问题:如何使用此令牌获取帐户信息?我必须发送什么请求才能做到这一点?
我已经尝试过这里的方法:https://developers.google.com/youtube/v3/guides/auth/installed-apps
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded
code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id=your_client_id&
client_secret=your_client_secret&
redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob%3Aauto&
grant_type=authorization_code
但我在developer console 中的chrome oauth2 app 甚至没有client_secret,所以看起来不像我的方式。
在getAuthToken() tutorial (https://developer.chrome.com/docs/extensions/mv2/tut_oauth/) 中,他们使用 google people API 并以这种方式对其进行验证:
let init = {
method: 'GET',
async: true,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
'contentType': 'json'
};
fetch(
'https://people.googleapis.com/v1/contactGroups/all?maxMembers=20&key=<API_Key_Here>',
init)
.then((response) => response.json())
.then(function(data) {
console.log(data)
});
如果我将范围更改为 contacts.readonly 但我需要 youtube.readonly 并且我不明白我必须在哪里发送类似的请求来获取我需要的信息,它对我有用。有人可以帮忙吗?
【问题讨论】:
标签: javascript google-chrome-extension google-api youtube-api youtube-data-api