Using the youtube livestream API with a youtube partner channel - youtube-api

I remain perpetually stumped on this one. I have a youtube channel, of which, I am an owner. I have been using OAuth2 and authenticate to my owner account, then provide access to my youtube account with the following access domains
https://www.googleapis.com/auth/youtubepartner, https://www.googleapis.com/auth/youtube.force-ssl, https://www.googleapis.com/auth/youtube.readonly, https://www.googleapis.com/auth/youtube
I issue the youtube.liveStreams().list command in the python google api interface with a variety of parameters but never do I get back a useful piece of information.
I currently have an unlisted stream running, DsjbycJHosw.
list_streams_request = youtube.liveStreams().list( part="snippet", id="DsjbycJHosw" )` responds with `{'etag': '"m2...gE"', 'kind': 'youtube#liveStreamListResponse', 'items': [], 'pageInfo': {'totalResults': 0, 'resultsPerPage': 5}}
list_streams_request = youtube.liveStreams().list( part="snippet", mine="true" )` responds with `{'etag': '"m2...gE"', 'kind': 'youtube#liveStreamListResponse', 'items': [], 'pageInfo': {'totalResults': 0, 'resultsPerPage': 5}}
list_streams_request = youtube.liveStreams().list( part="snippet", broadcastStatus="all" ) gives me a python error. Looks like the Python API doesn't support that. TypeError: Got an unexpected keyword argument "broadcaststatus
list_streams_request = youtube.liveStreams().list( part="snippet", onBehalfOfContentOwner="[Channel Youtube UserID (base64)]" )` responds with `b'{\n "error": {\n "errors": [\n {\n "domain": "youtube.parameter",\n "reason": "missingRequiredParameter",\n "message": "No filter selected. Expected one of: mine, id, default",\n "locationType": "parameter",\n "location": ""\n }\n ],\n "code": 400,\n "message": "No filter selected. Expected one of: mine, id, default"\n }\n}\n'
Ok, so, I need to give it something in conjunction with my channel's ID, right? Let's add a "mine"=true.
list_streams_request = youtube.liveStreams().list( part="snippet", onBehalfOfContentOwner="[Channel Youtube User ID(base64)]", mine="true" )` responds with `b'{\n "error": {\n "errors": [\n {\n "domain": "youtube.parameter",\n "reason": "invalidMine",\n "message": "The \\u003ccode\\u003emine\\u003c/code\\u003e parameter cannot be used in requests where the authenticated user is a YouTube partner. You should either remove the \\u003ccode\\u003emine\\u003c/code\\u003e parameter, authenticate as a YouTube user by removing the \\u003ccode\\u003eonBehalfOfContentOwner\\u003c/code\\u003e parameter, or act as one of the partners channels by providing the \\u003ccode\\u003eonBehalfOfContentOwnerChannel\\u003c/code\\u003e parameter if available for the called method.",\n "locationType": "parameter",\n "location": "mine"\n }\n ],\n "code": 400,\n "message": "The \\u003ccode\\u003emine\\u003c/code\\u003e parameter cannot be used in requests where the authenticated user is a YouTube partner. You should either remove the \\u003ccode\\u003emine\\u003c/code\\u003e parameter, authenticate as a YouTube user by removing the \\u003ccode\\u003eonBehalfOfContentOwner\\u003c/code\\u003e parameter, or act as one of the partners channels by providing the \\u003ccode\\u003eonBehalfOfContentOwnerChannel\\u003c/code\\u003e parameter if available for the called method."\n }\n}\n'
Really? Come on now, Mr. API. What about if I use onBehalfOfContentOwnerChannel?
list_streams_request = youtube.liveStreams().list( part="snippet", onBehalfOfContentOwnerChannel="[My base64 channel ID]" )` yeilds `b'{\n "error": {\n "code": 500,\n "message": null\n }\n}\n'
And every combination I can think of just gives me tons of error code 500's.
I also can't seem to set forContentOwner in the python API, so no dice there. How is one supposed to do this?

This is no longer an issue. As of Jan, 2018, they've resolved it. The APIs behave exactly as expected as youtube partners can do the oauth permissions, now.

Related

YouTube Content ID API returns Forbidden error

I've created a service account for use with the YouTube Content ID API, I'm following the steps under Set up your service account on:
https://developers.google.com/youtube/partner/guides/oauth2_for_service_accounts
The steps seem to be a bit outdated, I am not able to find YouTube Content ID API in Developer console.
I am able to upload a video on a channel.
Well, when I'm making requests using this service account, I'm getting forbidden errors. For example the below error is when I'm trying to get a list of content owners.
error::::::{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission: Request had insufficient authentication scopes."
}
],
"code": 403,
"message": "Insufficient Permission: Request had insufficient authentication scopes."
}
}
Here's the PHP code:
$client = new Google_Client();
$client->setAccessType("offline");
$client->setApprovalPrompt("force");
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes(array('https://www.googleapis.com/auth/youtube', 'https://www.googleapis.com/auth/youtubepartner'));
$youtube = new Google_Service_YouTube($client);
$youtubePartner = new Google_Service_YouTubePartner($client);
$contentOwnersListResponse = $youtubePartner->contentOwners->listContentOwners(
array('fetchMine' => true));
$contentOwnerId = $contentOwnersListResponse['items'][0]['id'];
You have mentioned that you cannot see the "YouTube Content ID API" in your Google Developers Console, I think you need to check the YouTube Partner Program. Please do take note that "The YouTube Content ID API is intended for use by YouTube content partners and is not accessible to all developers or to all YouTube users". It was stated in the note at the top most of the page.

Google Youtube API nextPageToken

I have read a lot of the other post about using the nextPageToken with the Youtube API.
The reference I am using is
https://developers.google.com/apis-explorer/?hl=en_US#p/youtube/v3/youtube.commentThreads.list?part=snippet&maxResults=100&order=time&videoId=xyvQaVUeu90&fields=items(id%252Csnippet%252FtopLevelComment%252Fsnippet%252FtextDisplay)%252CnextPageToken&_h=35&
The video id i am using is xyvQaVUeu90
The script I run returns a nextPageToken as
QURTSl9pMm1EbHlJZFdJTENzcHpIMGI3VWllOVl0enBxREN3NlZSYzAzZVdQTkNKNV9XQkpmQTNYLWhhVDIzeGN5eUdXUDZqWUJkdFdBOGdKVksyOENUU3B4b014Yi12Y05PdGRRcVlTaHp3VXEyR0JxRFVYMm5rWG1sbUZsRmk
So according to the API, if I use that nextPageToken it should return the next page of comments, however when I place the nextPageToken as the pageToken
Reference:
https://developers.google.com/apis-explorer/?hl=en_US#p/youtube/v3/youtube.commentThreads.list?part=snippet&maxResults=100&order=time&pageToken=QURTSl9pMm1EbHlJZFdJTENzcHpIMGI3VWllOVl0enBxREN3NlZSYzAzZVdQTkNKNV9XQkpmQTNYLWhhVDIzeGN5eUdXUDZqWUJkdFdBOGdKVksyOENUU3B4b014Yi12Y05PdGRRcVlTaHp3VXEyR0JxRFVYMm5rWG1sbUZsRmk&videoId=xyvQaVUeu90&fields=items(id%252Csnippet%252FtopLevelComment%252Fsnippet%252FtextDisplay)%252CnextPageToken&_h=36&
It returns:
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "invalidPageToken",
"message": "The request specifies an invalid page token.",
"locationType": "parameter",
"location": "pageToken"
}
],
"code": 400,
"message": "The request specifies an invalid page token."
}
}
Any help would be nice!
It's working perfectly. Just make sure to copy everything between the double quotes ("") . I was able to use it without problems. For example the nextPageToken provided in your link is
"QURTSl9pMFZuQUJYNGc4dDVZRjRjYlJ3d0M1MlIzeTRSeEJfclZOeEEzdncxRVM4bGZFOXdIRVVVRkJibjBSVW5xaEtBTE1zS0VTd2lDNndrRmJQaG4tY1dScXFral9hMVQ3NmJidFI1Vk83a0xhWEJNU2cwMlYweERGLU1uMDhLazg="
but you only copied
QURTSl9pMFZuQUJYNGc4dDVZRjRjYlJ3d0M1MlIzeTRSeEJfclZOeEEzdncxRVM4bGZFOXdIRVVVRkJibjBSVW5xaEtBTE1zS0VTd2lDNndrRmJQaG4tY1dScXFral9hMVQ3NmJidFI1Vk83a0xhWEJNU2cwMlYweERGLU1uMDhLazg
You did not include =

Youtube API: Get videos from autogenerated channels (like Music)

Is there any way to get the videos from autogenerated channels (like this one https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ/videos) directly, without having to access all the playlists?
Using https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&key=... gives me 0 items.
Gives me 0 Items
If you mean running the following exactly
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&key=
Returns the following error
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
That is because you have neglected to add an API key on the end.
Try testing in the query explorer this seams to return quite a few no idea if its all of them.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&maxResults=25&key={YOUR_API_KEY}
returns
"pageInfo": {
"totalResults": 786,
"resultsPerPage": 25
},
This apears to return a list of the playlists only for this user.
Update:
If you try and only request videos for this user you get 0 returned. This is not the case for any other user which i have tested.
GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&maxResults=50&order=date&type=video&key={YOUR_API_KEY}
This leads me to believe that it is not possible to retrieve the videos for an autogenerated channel. I recommend either logging this as a bug or adding it as a feature request here. Personally i think its more a feature request.

400 Bad Request while fetching videos of a particular youtube channel

I want to get list of videos of a particular YouTube channel.
I followed this SO answer https://stackoverflow.com/a/20795628/5383573
Every time I am getting
400 Bad Request
Suppose I want to get all the video of NDTV Channel.
Its YouTube url is https://www.youtube.com/user/ndtv/videos
I went to this URL https://developers.google.com/youtube/v3/docs/playlists/list
Fill the boxes as
Part: NDTV
Channel ID:ndtv
Max Result: 50
and click Execute
It gives me Request as
GET https://www.googleapis.com/youtube/v3/playlists?part=ndtv&channelId=ndtv&maxResults=50&key={YOUR_API_KEY}
And response
400 Bad Request
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unknownPart",
"message": "ndtv",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "ndtv"
}
}
How can I get all the videos in JSON response?
Sorry for my bad English.
Any help will be appreciated.Thanks in advance
Playlists: list has five valid parts
The list below contains the part names that you can include in the
parameter value and the quota cost for each part: contentDetails: 2
id: 0 player: 0 snippet: 2 status: 2
A your error message states ndtv is not valid part. NDTV is also not a valid channel id. A channel id looks like this UCtb0gXU-ht24V_fgeXGGjwA
The easest way tof ind the channel id is to check YouTube
https://www.youtube.com/channel/UCtb0gXU-ht24V_fgeXGGjwA
NDTV has 3 featured channels, those with channel_id
UCZFMm1mMw0F81Z37aaEzTUA,UC9CYT9gSNLevX5ey2_6CK0Q,UCf9StUUEcbRpbvpdKx5eS_g
The following GET requests will return json response.
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId={ndtv_channel_id}
replace ndtv_channel_id with the channel id.

trying to show more than 50 results corresponding to single topic id using freebase in android

I want to get more than 50 youtube video results corresponding to topic id ........so i am trying to get next page token.......
in youtube api v3 in android
and url used is....
https://www.googleapis.com/youtube/v3/videos?part=id,snippet&order=relevancee&topicId="+topicId+"&q="+videoId+"&key="
but the error giving is......
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected."
}
}
You should set type = video
Whenever you are using a video specific filter you have to filter type as well. As search is unified, otherwise it normally returns playlist, channel and videos as a result.
You can always try your queries in API explorer before implementing.

Resources