Hello i Would like to know somethink.
i follow the steps on the website https://developers.google.com/youtube/analytics/v1/sample-application#Enable_Authentication>
First, in your file index.js
you forgot to close the function. The file need to be ended with
})();
Second point, why don't try with the exemple on the doc ? i see you use the js of the doc but you change the index.html. Try with the simple example of the doc, it's much better to help you to solve your problem. Check if you see the error again, then check in your http://console.developers.google.com, make sure you have the good settings for your project.
You need to activate :
YouTube Analytics API
YouTube Data API v3
You also need a credential, to have your client ID.
I try at home, with a my client ID and it works perfectly. Try this code with your client ID and see what append.
http://jsbin.com/gokovoje/3/edit?html,js,output
EDIT
Replace the function checkAuth()
by this :
function checkAuth() {
gapi.auth.authorize({
client_id: OAUTH2_CLIENT_ID,
scope: OAUTH2_SCOPES,
immediate: false
}, handleAuthResult);
}
EDIT 2°
More than 5 videos use maxResults
The maxResults parameter specifies the maximum number of items that should be returned in the result set. (integer, 0-50)
Add maxResults
to the function getPlaylistItems(listId)
// Calls the Data API to retrieve the items in a particular playlist. In this
// example, we are retrieving a playlist of the currently authenticated user's
// uploaded videos. By default, the list returns the most recent videos first.
function getPlaylistItems(listId) {
// https://developers.google.com/youtube/v3/docs/playlistItems/list
var request = gapi.client.youtube.playlistItems.list({
playlistId: listId,
part: 'snippet',
maxResults: 30
});
request.execute(function(response) {
if ('error' in response) {
displayMessage(response.error.message);
} else {
if ('items' in response) {
// jQuery.map() iterates through all of the items in the response and
// creates a new array that only contains the specific property we're
// looking for: videoId.
var videoIds = $.map(response.items, function(item) {
return item.snippet.resourceId.videoId;
});
// Now that we know the IDs of all the videos in the uploads list,
// we can retrieve info about each video.
getVideoMetadata(videoIds);
} else {
displayMessage('There are no videos in your channel.');
}
}
});
}