问题描述
我正在使用oauth.io( https://oauth.io/)通过Google对用户进行身份验证, facebook等.验证后如何向用户订阅youtube频道?
I'm using oauth.io (https://oauth.io/) to authenticate users via google, facebook, etc. How can I subscribe user to youtube channel after authentication ?
OAuth.popup(provider, function(error, result) {
// some code to subscribe user to youtube channel
});
推荐答案
要将用户订阅到youtube频道,您需要确保已将Youtube的以下范围添加到OAuth.io应用中:
To subscribe a user to a youtube channel, you need to make sure that you have added the following scopes for Youtube to your OAuth.io app:
- https://www.googleapis.com/auth/youtube
- https://www.googleapis.com/auth/youtubepartner
还要确保在您的Google API控制台中激活了YouTube API.
Also make sure that the Youtube API is activated in your Google API console.
然后,您可以像这样通过OAuth.io订阅用户:
Then, you can subscribe the user through OAuth.io like this:
OAuth.popup('youtube')
.done(function (requestObject) {
requestObject.post('/youtube/v3/subscriptions?part=snippet', {
data: JSON.stringify({
snippet: {
resourceId: {
channelId: 'id_of_the_channel'
}
}
}),
dataType: 'json',
contentType: 'application/json; charset=utf8'
})
.done(function (r) {
// Success: the subscription was successful
console.log(r);
})
.fail(function (e) {
// Failure: the id was wrong, or the subscription is a duplicate
console.log(e);
});
})
.fail(function (e) {
// Handle errors here
console.log(e);
});
您需要指定dataType和contentType字段,因为Google API不接受表单编码的数据.
You need to specify the dataType and contentType fields as Google API doesn't accept form encoded data.
您可以在此处找到有关此Google API终结点的更多信息:
You can find more information about this Google API endpoint there:
如果您想了解有关OAuth.io的更多信息,可以在这里查阅文档:
And if you want to learn more about OAuth.io, you can consult the documentation here:
您还可以在此处找到有关JavaScript SDK的教程:
You'll also find a tutorial about the JavaScript SDK here:
希望这会有所帮助:)
这篇关于oauth.io订阅用户到YouTube频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!