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
Please be sure your DOM has been loaded before launching this script tutorial.
If you have a doubt, just put all the <script>
tags just before the closing </body>
tag.
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.');
}
}
});
}
I had the same issue while using the youtube data api v3.
Just follow the steps :
function checkAuth() { gapi.auth.authorize({ client_id: OAUTH2_CLIENT_ID, scope: OAUTH2_SCOPES, immediate: false }, handleAuthResult); }
Once step 1 is followed u might get an error of unknow_client(thats the core issue actually)
2 So go to google developers console.For your project go to APIs and Auths>Consent screen> and provide the email address and product name.
3 Save it. Now try executing the code.