'YouTube Analytics with Google Apps Script for a Brand Account
Hey I am trying to get the YouTube Analytics for a Brand Account. I am using Google Apps Script but now I have the problem that i always get the information for the Google Account not the Brand Account. At the Moment I am using this code.
function retrieveMyUploads() {
var results = YouTube.Channels.list('contentDetails', {mine: true});
for(var i in results.items) {
var item = results.items[i];
// Get the playlist ID, which is nested in contentDetails, as described in the
// Channel resource: https://developers.google.com/youtube/v3/docs/channels
var playlistId = item.contentDetails.relatedPlaylists.uploads;
var nextPageToken = '';
// This loop retrieves a set of playlist items and checks the nextPageToken in the
// response to determine whether the list contains additional items. It repeats that process
// until it has retrieved all of the items in the list.
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken
});
for (var j = 0; j < playlistResponse.items.length; j++) {
var playlistItem = playlistResponse.items[j];
Logger.log('[%s] Title: %s',
playlistItem.snippet.resourceId.videoId,
playlistItem.snippet.title);
}
nextPageToken = playlistResponse.nextPageToken;
}
}
}
It would be great if someone could help me getting the information of the Brand Account and not the Google Account.
Solution 1:[1]
I don't know how YouTube recommends to get the authorization token but here is how I took it for a brand account:
Log in to the associated Google account on https://developers.google.com/youtube/v3/docs/channels/list then on the right pane, fill snippet for part and true to mine, open the network tab of your web browser (Ctrl + Maj + E), click execute at the bottom of the right pane then select the account you are connected with and then the brand account and get from the XHR request from the network tab the AUTHORIZATION_TOKEN that is given for the authorization header.
Then you can run this shell command to make sure you got the right AUTHORIZATION_TOKEN to meet your needs.
curl 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&mine=true' --header 'Authorization: Bearer AUTHORIZATION_TOKEN'
In the response you should see the name of your brand account so you can then modify the endpoint to meets your needs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Benjamin Loison |
