Why am I getting a page token error while using the live chat API? - youtube-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).

Related

Outlook Oauth .default suffix error trying smtp and imap after getting token

Im trying to access an Outlook email using Oauth , Already set this permissions on Azure App:
So, using Oauth 2.0 client credentials grant I obtain the access Token:
But, when I try to authenticate with that token it fails, so I read that it was necessary to generate a second token call using that first one as a parameter and using imap and smtp scopes concatenated, and I tried like in the examples:
And as you see, I get this suffix error :
{
"error": "invalid_scope",
"error_description": "AADSTS1002012: The provided value for scope https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send
is not valid. Client credential flows must have a
scope value with /.default suffixed to the resource identifier (application ID URI).\r\nTrace ID: 41d2086b-f83e-41d8-b405-115249b27901\r\nCorrelation ID: 6afef855-3fc9-4259-864b-4ec8e293e9d0\r\nTimestamp: 2022-04-29 00:02:06Z",
"error_codes": [
1002012
],
"timestamp": "2022-04-29 00:02:06Z",
"trace_id": "41d2086b-f83e-41d8-b405-115249b27901",
"correlation_id": "6afef855-3fc9-4259-864b-4ec8e293e9d0"
}
Any idea what am I doing wrong ?, why the first token its not enough or how do I get the access one in the second call ?
Thanks in advance !!

"AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token" Az API Management

I am trying to obtain an authorization token to consume a published API in Azure API Management, for which I am performing the following steps:
Call the authorization URL as follows:
https://login.microsoftonline.com/common/oauth2/authorize?
client_id=<CLIENT_ID>
&response_type=code
&response_mode=query
&redirect_uri=<REDIRECT_URI>
&scope=SCOPE
Immediately after, I call the following URL with the obtained authorization code and other parameters in the body and to send them as form-data:
POST https://login.microsoftonline.com/common/oauth2/token
client_id=<CLIENT_ID>
scope=SCOPE
grant_type=authorization_code
client_secret=<CLIENT_SECRET>
code=<AUTHORIZATION_CODE_PREVIOUS_STEP>
As a result, I get the following error and cannot continue:
{
"error": "invalid_grant",
"error_description": "AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token.\r\nTrace ID: f0264d85-2f41-4009-9e8e-1a211209e100\r\nCorrelation ID: c6b15ffb-82e8-49aa-941f-6c85be4d9601\r\nTimestamp: 2022-01-18 15:06:55Z",
"error_codes": [
54005
],
"timestamp": "2022-01-18 15:06:55Z",
"trace_id": "f0264d85-2f41-4009-9e8e-1a211209e100",
"correlation_id": "c6b15ffb-82e8-49aa-941f-6c85be4d9601"
}
I understand that the authorization code is for one use only but, in my case, on the first attempt I get this error.
Any help is appreciated

YouTube Data API V3 unkownPart "localizations"

I have been trying to fetch all videos from a playlist using YouTube Data API, which worked like a char; next, I wanted to try and filter videos based on languages, so I wanted to try to include the "localizations" part. However, whenever I do, I get a 400 response stating that "localizations" is "unkownPart". From what I could see in the documentation, I should have my GET request structured properly:
`https://youtube.googleapis.com/youtube/v3/playlistItems?part=localizations&part=snippet&maxResults=${limit}&playlistId=${playlistId}&key=${apiKey}`
Error message in postman:
{
"error": {
"code": 400,
"message": "'localizations'",
"errors": [
{
"message": "'localizations'",
"domain": "youtube.part",
"reason": "unknownPart",
"location": "part",
"locationType": "parameter"
}
]
}
}
"localizations" is a direct copy from the documentation. The GET request works fine if I remove it so I'm confident that the problem is either the order or my parameters, or the combinations of parameters in use (though I couldn't find anything about incompatible parameters in the documentation).
Parameters order goes as follows:
localizations
snippet
playlistId
key
EDIT: link to the documentation: https://developers.google.com/youtube/v3/docs/playlists/list
After sending the Issue Report it was discovered that I had been using the wrong API endpoint. Somehow (I can't remember why) I was using the "playlistItem" endpoint which doesn't support "localizations", and needed to shift to using the "playlists" endpoint instead.
Furthermore when using a combination of both "snippet" and "localization", they should be within the same parameter but comma-separated, however, Postman doesn't auto-convert the commas in the parameters to "%2C" and therefore would cause further trouble understanding the requests. Fixing these 2 steps, it now works as intended.

How to get list of all subscribed channels of user using youtube api?

I am using Laravel-php, I have following code :
$client = new Google_Client();
$client->setClientId(env('GOOGLE_ID'));
$client->setClientSecret(env('GOOGLE_SECRET'));
//$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/youtube.force-ssl");
$client->addScope("https://www.googleapis.com/auth/youtube");
$client->addScope("https://www.googleapis.com/auth/youtube.readonly");
$client->addScope("https://www.googleapis.com/auth/youtubepartner");
$youtube = new \Google_Service_YouTube($client);
$searchResponse = $youtube->channels->listChannels('snippet', array('mine' => true));
//$subscriptions = Curl::to('https://www.googleapis.com/youtube/v3/subscriptions')->withData(['part' => 'snippet', 'mine' => 'true'])->get();
echo "<pre>";
print_r($searchResponse);
Above code gives me following error :
Google_Service_Exception in REST.php line 118:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
I have tried to use CURL call also but that also gives me same error, any suggestions will save my day
What am I missing in code ?
Your error means that you haven't set up a Google APIs console project. The resource you are accessing requires OAuth authorization. You need to obtain authorization credentials in the Google Developers Console to be able to use OAuth 2.0 authorization.
Open the Credentials page.
The API supports API keys and OAuth 2.0 credentials. In your case, use OAuth 2.0 for your project:
OAuth 2.0: Your application must send an OAuth 2.0 token with any request that accesses private user data. Your application sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.
See the Creating OAuth 2.0 credentials section for more information.
You may also check this related thread: list user subscriptions to all youtube channels after getting access token
First thing is that it needs to be an authenticated call.
So you need to get the person to "Authenticate" through the Oauth2 and collect the token.
Then with the token send this call
https://www.googleapis.com/youtube/v3/subscriptions?part=id,snippet,contentDetails&maxResults=50&channelId='.$channelId.'&access_token='.$access_token
Then you can access the JSON response and collect them.

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

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

Resources