我的问题是试图准确确定我需要做些什么来为用户添加订阅。
我将这些脚本添加到我的html
<!-- Youtube platform start -->
<script type="text/javascript" src="https://apis.google.com/js/platform.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
我的脚本如下:
// Get browser location
$scope.currentUrl = window.location.origin + window.location.pathname;
// get Channel Id
var channelId = CHANNEL_ID_HERE;
// Call to Youtube API for channel thumbnail, name, description, and subscribers
$http({
method: 'GET',
url: 'https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet&id=' + channelId + '&key={API_KEY}'
}).then(function successCallback(response) {
console.log(response);
$scope.channelThumbnail = response.data.items[0].snippet.thumbnails.default.url;
$scope.channelName = response.data.items[0].snippet.title;
$scope.channelDesc = response.data.items[0].snippet.description;
$scope.channelSubs = response.data.items[0].statistics.subscriberCount;
}, function errorCallback(response) {
console.log(response);
});
function initClient() {
gapi.client.init({
apiKey: 'API_KEY',
clientId: 'CLIENT_ID',
scope: 'profile',
}).then(function () {
console.log("gapi initialized");
});
}
gapi.client.load('youtube', 'v3', initClient);
$scope.addSubscription = function () {
var resource = {
part: 'snippet',
snippet: {
resourceId: {
kind: 'youtube#channel',
channelId: channelId
}
}
};
var request = gapi.client.youtube.subscriptions.insert(resource);
request.execute(function (response) {
var result = response.result;
if (result) {
alert("Subscription completed");
}
else {
alert("Subscripion failed");
}
}
);
}
请假装clientID和ApiKeys在那里。当我调用addSubscription函数时,这是发出的调用:https://content.googleapis.com/youtube/v3/subscriptions?part=snippet&alt=json&key=APIKEY。我没有正确地初始化某些东西,还是还有其他东西需要完成这个POST?我已经阅读了很多文档,但似乎无法找到原因并不会成功。我的GET请求工作得很好,但我似乎无法获得POST请求。
提前致谢。