【发布时间】:2021-12-17 11:18:00
【问题描述】:
因此,根据https://developers.google.com/youtube/v3/guides/working_with_channel_ids,每个帐户都包含一个唯一的频道 ID,该 ID 与过去的用户名无关。这一切都很好,因为频道 ID 是识别唯一帐户的方法。当然,我完全赞成。我感到困惑的是,当我获得一个唯一的频道 ID 时,我如何使用它来获取频道首选的“用户名”,无论是一些在线别名还是“现实生活”名称?
具体来说,我正在使用这个 API (https://developers.google.com/youtube/v3/live/docs/liveChatMessages/list?hl=en) 来定期观看新消息被放入我的广播。它可以工作,并提供如下所示的数据:
{
kind: 'youtube#liveChatMessage',
etag: 'zPV9PwBFYCiNZH_4PpspXF0ZrSs',
id: 'LCC.CikqJwoYVUNMcnBlSWl1aVF1WHphcldCZVFuc3dBEgtOaHI4d2NSUHIyQRI5ChpDTC0ybDQzcC12TUNGVVFCZlFvZDVBQUhiQRIbQ09YRjdfM2stdk1DRmZRYmZRb2QzT0FCUUEw',
snippet: {
type: 'textMessageEvent',
liveChatId: 'KicKGFVDTHJwZUlpdWlRdVh6YXJXQmVRbnN3QRILTmhyOHdjUlByMkE',
authorChannelId: 'UCLrpeIiuiQuXzarWBeQnswA',
publishedAt: '2021-11-02T23:22:37.070185+00:00',
hasDisplayContent: true,
displayMessage: 'testing once again ????',
textMessageDetails: [Object]
}
}
如您所见,这里有一个authorChannelId,这很棒...除了我无法以人类的身份合理地阅读这一事实。
我的用例是我特别希望有一个定期更新的本地应用程序,它可以使用类似格式的控制台消息更新我:
Bob Frank: foo bar :D
尽管我在技术上可以拥有类似以下的内容,但这并不能帮助我知道我的 5 个朋友中的哪一个我会在我的直播中期待:
UCLrpeIiuiQuXzarWBeQnswA: foo bar :D
啊,是的……你又是谁?能再提醒一下UCLrpeIiuiQuXzarWBeQnswA吗?
我也尝试了以下 API (https://developers.google.com/youtube/v3/docs/channels/list),但它似乎也没有提供正确的信息。使用part: "snippet" 和id: "UCLrpeIiuiQuXzarWBeQnswA" 我得到以下输出:
{
config: {
url: 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=UCLrpeIiuiQuXzarWBeQnswA',
method: 'GET',
userAgentDirectives: [ [Object] ],
paramsSerializer: [Function (anonymous)],
headers: {
'x-goog-api-client': 'gdcl/5.0.5 gl-node/17.0.1 auth/7.10.1',
'Accept-Encoding': 'gzip',
'User-Agent': 'google-api-nodejs-client/5.0.5 (gzip)',
Authorization: 'Bearer',
Accept: 'application/json'
},
params: { part: 'snippet', id: 'UCLrpeIiuiQuXzarWBeQnswA' },
validateStatus: [Function (anonymous)],
retry: true,
responseType: 'json'
},
data: {
kind: 'youtube#channelListResponse',
etag: 'wjX6CX2hdUPFAc4y6OCUDDjXT6o',
pageInfo: { totalResults: 1, resultsPerPage: 5 },
items: [ [Object] ]
},
headers: {
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
'cache-control': 'private',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Wed, 03 Nov 2021 01:30:32 GMT',
server: 'scaffolding on HTTPServer2',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin, Referer',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0'
},
status: 200,
statusText: 'OK',
request: {
responseURL: 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=UCLrpeIiuiQuXzarWBeQnswA'
}
}
因此,我们将不胜感激任何帮助!谢谢!
编辑:删除访问令牌。哎呀。
Edit2:答案在问题中,但下面接受的答案有所帮助。谢谢本杰明!真正的答案是进一步了解上面的最终响应...... response.data.items[0].sn-p.title。在这种情况下,nodejs console.log() 没有展开每个项目,我完全错过了这个细节。我的错,我是节点和 javascript 的新手。您也可以使用 Benjamin 指出的 API 密钥,但此时我已经可以访问 Oauth2,所以我将继续使用相同的身份验证。
【问题讨论】:
标签: youtube-api youtube-data-api youtube-livestreaming-api