I want to get a logged in user's private YouTube video details using the v3 API. I have already extended my Google Oauth authentication with YouTube scope. The login process was success. The owner of the private video is the logged in user.
However if I use the following request I got a valid success message but with a 0 result.
My request:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet&id=VIDEO_ID&key=API_KEY
Response:
{
"kind": "youtube#videoListResponse",
"etag": "\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 0
},
"items": []
}
Any idea what can be the problem?
Finally I have found the problem. The Google OAuth access token was not part of the request header. After including it in the request the response gave me the correct result.
Related
I'm not sure if this is an inconsistency of YouTube's Data API or just a bad naming of a YouTube error.
There's a public channel on YouTube without any content:
https://www.youtube.com/channel/UCvAHk_1_TMmq6SW0XA9BcgA.
If I query Channels:list (query) with this channel ID UCvAHk_1_TMmq6SW0XA9BcgA, I get the following response:
{
"items": [
{
"id": "UCvAHk_1_TMmq6SW0XA9BcgA",
"snippet": {
"title": "level10store0"
},
"status": {
"privacyStatus": "public",
"isLinked": true,
"longUploadsStatus": "longUploadsUnspecified"
}
}
]
}
If I query for all playlists of this channel via Playlists:list (query) I get this response:
{
"kind": "youtube#playlistListResponse",
"etag": "iziRvpOe3rkNWHlySTxLgAk4dJI",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
But using YouTube's PHP client with Playlist:list you'll get a response error with following information:
domain=youtube.playlist, reason=channelNotFound, location=channelId,
locationType=parameter
Why does YouTube's PHP client give a channelNotFound error instead of an empty response like YouTube's data explorer does?
Update 1:
YouTube's data API delivered a channel on the OAuth handshake initialized by the user itself. My application asked for an offline access token for further requests. If I use this access token I experience the above mentioned behaviour. I think the token is valid as I use the identical process for many other users. If the token would not be valid I would have got an error message like global.authError or youtube.header.youtubeSignupRequired.
My code looks like this (which works for many other users):
$youtubeClient->playlists->listPlaylists(
'snippet,contentDetails',
array(
'maxResults' => 50,
'channelId' => $channelId,
'pageToken' => $nextPlaylistPageToken,
'fields' => 'etag,items(id,etag,snippet(publishedAt,channelId,thumbnails/default,title),contentDetails(itemCount)),nextPageToken'
)
);
Remember that YouTube is channel based and not user based. When the user logs in they pick which channel to access. When the user consented access to your application on PHP they did not pick the correct channel so there for do not have access to the data on that channel.
Log the user out and consent access again this time picking the correct channel.
In a project I am provided with API endpoints from a Firebase DB.
To retrieve data I authenticate a user with email and password (https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-email-password) and then sign every API call with the token. (These users are set up in Firebase DB)
Now one of the API endpoints returns Firebase Storage objects like this:
"fileReferences": [
{
"id": "",
"name": "images\/-s0m31D\/picture.jpg",
"mediaLink": "https:\/\/www.googleapis.com\/download\/storage\/v1\/b\/BUCKET.appspot.com\/o\/images%2F-s0m31D%2Fpicture.jpg?generation=1537959346600572&alt=media",
"selfLink": "https:\/\/www.googleapis.com\/storage\/v1\/b\/BUCKET.appspot.com\/o\/images%2F-s0m31D%2Fpicture.jpg",
"updated": 1537959346,
"size": 7759448
}
],
when I try to access fileReferences.0.mediaLink, I get an auth error.
If I send my token along with the request to mediaLink I have no luck either (https://cloud.google.com/storage/docs/downloading-objects#download-object-json)
I tried to use the Google API PHP client https://github.com/googleapis/google-api-php-client, but had no idea how I setup the new Google_Client() (I already have my auth token and I expected it to work somehow)
$client = new \Google_Client();
$client->setAccessToken(['access_token' => $token]);
How can I access the media files with my existing auth token? (or do I need a different one?)
To handle the files, I would like to use https://github.com/googleapis/google-api-php-client how can I make that work? Any hint is appreciated
Edit: I got some results in debugging the JavaScript SDK
"All" the SDK does is creating the following URL Schema
printf('https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/%s', urlencode('projects/-id/logo.png'));
//http[s]://firebasestorage.googleapis.com/<api-version>/b/<bucket>/o/<object-path>
You have to sign the call to https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/projects%2F-id%2Flogo.png with your Auth Bearer token header![1]
This returns meta data like this:
{
"name": "projects/-id/logo.png",
"bucket": "bucket.appspot.com",
"generation": "1537960188874518",
"metageneration": "1",
"contentType": "image/png",
"timeCreated": "2018-09-26T11:09:48.874Z",
"updated": "2018-09-26T11:09:48.874Z",
"storageClass": "STANDARD",
"size": "40437",
"md5Hash": "MxkOU+6feyYtdEAgKbDgp5A==",
"contentEncoding": "identity",
"contentDisposition": "inline; filename*=utf-8''logo.png",
"crc32c": "o89Y9dQ==",
"etag": "CJae8pXE2N0CEAE=",
"downloadTokens": "32c339ff9-7e4a-42a2-890a-428f8f45d378"
}
To publicly share your image, add ?alt=media&token=32c339ff9-7e4a-42a2-890a-428f8f45d378
https://firebasestorage.googleapis.com/v0/b/bucket.appspot.com/o/projects%2F-id%2Flogo.png?alt=media&token=32c339ff9-7e4a-42a2-890a-428f8f45d378
You don't need the token, if you send the Auth Header!
I couldn't find any mention of firebase or how to deal with my authentication in https://github.com/googleapis/google-api-php-client, so I have no idea if this would have helped me. But I got down to the basics...
Hope this helps somebody and any clearification is greatly appreciated.
QUESTION for me to better understand this all:
What are mediaLink and selfLink pointing to?
[1] if the access to storage is public you don't need to sign it.
I used Microsoft Graph API PHP SDK to add user in my Azure Active Directory B2C. I managed to create users with a userPrincipalName like name#mytenantid.onmicrosoft.com.
I wasn't able to add users with a GMail address such as john.doe#gmail.com.
I tried to add the signInNames collection but I got the following response:
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:
POST https://graph.microsoft.com/v1.0/users resulted in a 400 Bad Request
response:
{ "error": {
"code": "Request_BadRequest",
"message": "Invalid property 'signInNames'.",
"innerError": (truncated...)
Here is my JSON request body :
{
"accountEnabled": true,
"displayName": "John Doe",
"userPrincipalName": "john#doe.fr",
"creationType": "LocalAccount",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "P#!ssWor?D"
},
"signInNames": [
{
"type": "emailAddress",
"value": "john#doe.fr"
}
]
}
You're confusing Microsoft Graph API with the Azure AD Graph API. These are two different APIs. While they share a lot of functionality, calls to these APIs are not interchangeable.
The User object in Microsoft Graph API doesn't support a signInNames property. This is why it is returning that error.
Local account users are not supported by Microsoft Graph API at the moment.
In case if someone will still have the same problem, in MS Graph Api you can use "identities" instead of "signInNames" and your JSON will look like
{
"accountEnabled":true,
"displayName":"John Doe",
"userPrincipalName":"john#doe.fr",
"creationType":"LocalAccount",
"passwordProfile":{
"forceChangePasswordNextSignIn":true,
"password":"P#!ssWor?D"
},
"identities":[
{
"signInType":"emailAddress",
"issuer":"<your tenant domain name>",
"issuerAssignedId":"john#doe.fr"
}
]
}
So I was wondering faecebook docs hasn't mention it in its official docs on Developers
but I have seen the graph call on blogs but it works (that's the weird thing)
https://graph.facebook.com/me/friends?method=post&uids=< USER ID>&access_token=< Acccess Token>
The respond is
{
"error": {
"message": "(#200) ",
"type": "OAuthException",
"code": 200
}
}
Is this possible to do? if yes, How can I do it with PHP SDK?
any idea is accepted
You can use the Friends Dialog. To integrate you can use javascript as-
FB.ui({
method: 'friends',
id: USER_ID
}, function(response){});
OR, a URL redirect as-
https://www.facebook.com/dialog/friends/?
id=USER_ID
&app_id=APP_ID
&redirect_uri=REDIRECT_URI
For more details: Friends Dialog
Since Youtube Api V2 doesn't support like a specific video anymore. Can anyone please explain how to like a video with youtube api v3 ?
I am always getting the following response:
Response
400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unexpectedPart",
"message": "contentDetails",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "contentDetails"
}
}
The request is :
Request
POST https://www.googleapis.com/youtube/v3/activities?part=snippet&key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.AHES6ZQUI8Gn7j93QZBmmdlDe7Ei-iqYseYAKAxyf3qTOHHwDHb-dA
X-JavaScript-User-Agent: Google APIs Explorer
{
"contentDetails": {
"like": {
"resourceId": {
"videoId": "video-id",
"kind": "youtube#video"
}
}
}
}
The part is = snippet
I am following these docs : https://developers.google.com/youtube/v3/docs/activities/insert
The answer is already in the comments, but to elevate it a bit: YouTube API v3: Liking a video in Python has more information about liking a video, though the example there is in Python.
The important part is that liking a video is done via a playlistItems.insert() call, not an activities.insert() call. This is a common source of confusion and I've already asked our tech writer to try to clear things up in the docs.