Why Youtube "channels" API don't return "contentOwnerDetails" data? - youtube-api

I'm trying to make this call to Youtube channels API but the response is without contentOwnerDetails. What is the problem?
GET https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2CcontentOwnerDetails&mine=true&key={YOUR_API_KEY}

It looks like it needs onBehalfOfContentOwner parameter. My request was
GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentOwnerDetails&id=CHANNEL_ID&onBehalfOfContentOwner=NETWORK_ID
And I was able to get
"contentOwnerDetails": {
"contentOwner": NETWORK_ID,
"timeLinked": "2015-07-23T15:21:25.000Z"
}

For your GET method URI
https://www.googleapis.com/youtube/v3/channels?part=id%2CcontentDetails%2CcontentOwnerDetails&mine=true&key={YOUR_API_KEY}
The JSON response is as follows
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "authorizationRequired",
"message": "The request uses the <code>mine</code> parameter but is not properly authorized.",
"locationType": "parameter",
"location": "mine"
}
],
"code": 401,
"message": "The request uses the <code>mine</code> parameter but is not properly authorized."
}
}
According to YouTube Data API - Errors
401 (unauthorized) - authorizationRequired - The request uses the mine
parameter but is not properly authorized.
mine parameter value has to be set to true to instruct the API to only return channels owned by the authenticated user. (boolean)
Inference: You don't have the authorization to the content from the content owner, i.e., the YouTube Channel owner has probably denied permission to your application from accessing the channels content.
It's a permission issue. Where is the channelId in the URI? should probably add it.

If you don't own the channel the API will not return contentOwnerDetails. Since you're using mine=true parameter, you need to be properly authorized via OAuth first before the API will return contentOwnerDetails. See https://developers.google.com/youtube/v3/guides/authentication

Related

Why am I getting a page token error while using the live chat API?

I'm trying to get the live chat of the live stream:
https://www.youtube.com/watch?v=xHtuITYCqcM.
So for that, I made the URL:
https://youtube.googleapis.com/youtube/v3/liveChat/messages?liveChatId=xHtuITYCqcM&key=...,
and it returns the following:
{
"error": {
"code": 400,
"message": "page token is not valid.",
"errors": [
{
"message": "page token is not valid.",
"domain": "youtube.liveChat",
"reason": "pageTokenInvalid"
}
]
}
}
If anyone knows why is this happening, please help me.
I'm new to this platform, so if I missed anything, please tell me.
According to the official specification of the LiveChatMessages.list API endpoint, its request parameter liveChatId is defined as follows:
liveChatId (string)
The liveChatId parameter specifies the ID of the chat whose messages will be returned. The live chat ID associated with a broadcast is returned in the liveBroadcast resource's snippet.liveChatId property.
Consequently, passing to this endpoint the respective stream's video ID -- xHtuITYCqcM -- is incorrect.
You'll have to invoke, as specified above, the LiveBroadcasts.list API endpoint, passing to it the request parameter id set to your stream's video ID -- that is xHtuITYCqcM -- by means of an URL like this one:
https://www.googleapis.com/youtube/v3/liveBroadcasts?id=xHtuITYCqcM&part=snippet&fields=items.snippet.liveChatId&access_token=$ACCESS_TOKEN
where $ACCESS_TOKEN is the access token obtained upon running to successful completion an OAuth 2.0 authentication/authorization flow.
Note that the OAuth flow is actually required (an API key does not suffice), because:
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope
https://www.googleapis.com/auth/youtube.readonly
https://www.googleapis.com/auth/youtube
https://www.googleapis.com/auth/youtube.force-ssl
Also note that above I used the fields request parameter for to get from the API only the info that's of actual use (a good practice).

Create Team, 400 Bad Request, Required functionality is not supported

I'm trying to create a Microsoft Teams team in Migration mode via the Graph API. However I get a 400 response that I can't figure out. The query is shared in the link below.
Shared Query
For those that don't want to view it that way, here is my request:
POST https://graph.microsoft.com/beta/teams
Authorization: Bearer ...
Content-Type: application/json
{
"#microsoft.graph.teamCreationMode": "migration",
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates(\u0027standard\u0027)",
"displayName": "SlackMigrationTest",
"description": "testing slack migrations",
"createdDateTime": "2021-01-14T00:00:00.000Z"
}
I created this based on the microsoft doc here.
The reponse I get is:
The remote server returned an error: (400) Bad Request.
{
"error": {
"code": "BadRequest",
"message": "Required functionality is not supported.",
"innerError": {
"date": "2021-01-20T15:51:21",
"request-id": "dc4189cf-db4a-4a60-a271-f63b5d759a05",
"client-request-id": "dc4189cf-db4a-4a60-a271-f63b5d759a05"
}
}
}
I'm sure its something obvious that I'm missing but any help would be greatly appreciated.
Here you are using the User Context token and trying to make the call. This API call only works in Application context as shown in the below screenshot.
So use Client Credential flow and set Application permissions and then make a call.
As you can see below, it worked for me with App token.
You cannot test it in graph explorer because the Graph Explorer gets user token.

forbiddenScope Error : while adding person in Google Plus circle via HTTP request

I want to add user in circle. I have retrieved access_token as described in Using OAuth 2.0 to Access Google APIs with scopes :
https://www.googleapis.com/auth/plus.me
https://www.googleapis.com/auth/plus.circles.read
https://www.googleapis.com/auth/plus.circles.write
https://www.googleapis.com/auth/plus.stream.write
Then i am calling HTTP request as described in Circles: addPeople
https://www.googleapis.com/plusDomains/v1/circles/<circleId>/people?userId=<userID>
but in response i am getting -
{
"error": {
"errors": [
{
"domain": "plusDomains",
"reason": "forbiddenScope",
"message": "Access to the Google+ Domains API is not allowed as the user has consented to incompatible scopes. See: https://developers.google.com/+/domains/authentication/."
}
],
"code": 403,
"message": "Access to the Google+ Domains API is not allowed as the user has consented to incompatible scopes. See: https://developers.google.com/+/domains/authentication/."
}
}
I have enabled Google+ API, Google+ Domains API in project's API's & Auth section.
Thanks in advance!

"Insufficient Permission" to retrieve user youtube subscriptipns after getting access token

I'm working on a scripts that checks if the user is already subscribed to my channel. The idea is to get all the channels the user had subscribed into then check if my channel id is one of them. First I get the access token correctly using POST and it works fine than send these as GET but the result is "failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden false". Doc page: https://developers.google.com/youtube/v3/docs/subscriptions/list#request_url
$data =file_get_contents('https://www.googleapis.com/youtube/v3/subscriptions?part=snippet
&maxResults=50&access_token='.$token.'&mine=true&key=My API Key');
var_export($data);
and pasting the full url
https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true&access_token={Access_Token}
I get this
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
Add a heaer:
Authorization: Bearer ya29.DwG_A_V6cybZ2KGqRwPMBF02w0sYw9msqSKoCBI53So0zzIHFRKlwEv68C4aI_NdadQ4wKHUrV2pBA
key is your client id
Google restricts access with API keys. If you go over the free limits, they charge you. You need to get a Google API key and add it to the URL like this: &key=YOUR_API_KEY
Create the API key from Google's console (you'll need to sign up and create a project): https://console.cloud.google.com/apis/credentials
Your new URL for the request would be:
https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true&access_token={Access_Token}&key=YOUR_API_KEY
I was having this error, and I solved it when I found out I needed to add the Youtube scope to my OAuth sign-in request: "https://www.googleapis.com/auth/youtube"

What is the proper way to list all youtube broadcasts on behalf of the Content Owner (Youtube Partner) using Youtube API V3?

I tried this:
Went here - https://developers.google.com/youtube/v3/docs/search/list
Set the following parameters:
part - snippet
eventType - live (Also tried, completed)
forContentOwner - true
onBehalfOfContentOwner - 'Partner ID'
type - video
I have properly authenticated using the partners login credentials by switching on the OAuth at the top right of the form.
The documentation says, if 'eventType' is set, then the 'type' should be set to 'video' and if 'forContentOwner' is set then onBehlafOfContentOwner should be supplied and should be properly authenticated all of which I clearly did but I get the following error:
400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.search",
"reason": "invalidSearchFilter",
"message": "Invalid combination of search filters and/or restrictions.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "Invalid combination of search filters and/or restrictions."
}
}
As it says in the debug info: video_filter is unsupported in combination with for_content_owner filter.
So you can not do it this way.

Resources