I'm trying to get video information (source URL, preview URL, title, description) using Facebook Graph API on Android. Everything work fine for friend's videos and some random public videos found on Facebook.
However, it doesn't work for videos uploaded using testing user accounts. These users are not in my friends list.
The HTTP query is:
GET graph.facebook.com/v2.3/{video-id}
The API returns:
{
"error":
{
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
This happens both when using Facebook SDK for Android and Graph API Explorer (https://developers.facebook.com/tools/explorer).
This doesn't happen if I use APP Token instead of user access token.
If I use video owner's access token I can see video details but then requests fail for my own videos.
Every tested video is "public". I can watch these videos on Facebook without any problem.
Edit: following permissions are requested: "public_profile", "publish_actions", "user_videos", "user_birthday", "user_friends", "email", "user_location"
What am I doing wrong?
Have a look at
https://developers.facebook.com/docs/graph-api/reference/video#Reading
It states:
You must use a valid Page Access Token or User Access Token for any video with public privacy settings.
For videos uploaded by someone, and any videos in which they have been tagged you need a user access token for that person with user_videos permission.
Related
I am currently using Facebook login for firebase auth for my android app and retriving user's photourl using
firebaseAuth.getCurrentUser().getPhotoUrl()
This gives me the photo url from the user's facebook profile.
Recently I have received mail from Facebook stating -
"Facebook will now require client or app access tokens to access a user’s profile picture when querying against user IDs. Beginning on October 24, 2020, queries for profile pictures made against user IDs without an access token will return a generic silhouette rather than a profile picture."
More on it on this link https://developers.facebook.com/blog/post/2020/08/04/Introducing-graph-v8-marketing-api-v8
My question -
Does the request firebaseAuth.getCurrentUser().getPhotoUrl() use access tokens to access url from facebook and will it function the same after the release of Graph API 8.0 on 24th Oct?
Or will I have to make a different query request to fetch the User's photo url for facebook provider?
Unfortunately, you'll have to add the access token to the photo url by yourself as Firebase does not and will not support it (as they don't have access to it - you can read more about it here).
You'll have to do something along the lines of:
firebaseAuth.getCurrentUser().getPhotoUrl() + "?access_token=<facebook_access_token>"
To be able to get the access token of facebook, after being logged-in with Firebase, you can use:
AccessToken.getCurrentAccessToken()
Complementing the answer of Marek Fort, with Kotlin you can get the picture doing something like that:
"${firebaseAuth.getCurrentUser().getPhotoUrl()}?access_token=${AccessToken.getCurrentAccessToken()}"
In kotlin it looks like:
"${firebaseAuth.currentUser?.photoUrl}?access_token=${AccessToken.getCurrentAccessToken()?.token}"
I have an Android application integrated with the deezer rest API, and I need to add a track to a playlist.
My application already has Oauth login flow, when I execute the following request:
http://api.deezer.com/user/me?access_token=AJSDH44H5R7SS7SDHDUHFSUDUSUSASDA766
Works fine!
Playlist actions, I trying send this request as:
POST
http://api.deezer.com/playlist/777006545/tracks?access_token=AJSDH44H5R7SS7SDHDUHFSUDUSUSASDA766&songs=2312333,12312
GET
http://api.deezer.com/playlist/777006545/tracks?access_token=AJSDH44H5R7SS7SDHDUHFSUDUSUSASDA766&songs=2312333,12312&request_method=post
Callback error:
{
"error": {
"type": "OAuthException",
"message": "An active access token must be used to query information about the current user",
"code": 200
}
}
But the token works for other requests. What's the right way to do this, anyone know?
Have you checked this page?
https://developers.deezer.com/api/playlist#actions ?
It seems you already have found this one:
https://developers.deezer.com/api/actions-post
Here is what I would test:
POST only.
Check that your access token has the manage_library permission.
Check that the owner of the playlist is the same that the user of the access_token.
It worked for me with:
http://api.deezer.com/playlist/<playlist_id>/tracks?access_token=<access_token>&request_method=post&songs=<track_id>
I am trying to authorize with OAuth2 to use YouTube data API. I want to write a simple client for Android to have a possibility, for example, get lists of user subscriptions, playlist etc.
The problem is that each method I try (e.g. HTTP requests like https://www.googleapis.com/youtube/v3/subscriptions or YouTube library com.google.apis:google-api-services-youtube:v3-rev120-1.19.0), I get the same error:
401 Invalid Credentials
I do these steps:
Register app in Google's console. Enable YouTube Data API. Create OAuth credentials with my app package name and keystore.
Create Android API Key.
And here I have a lot of questions.
To have a possibility to get user subscriptions etc. do I have to register the app with OAuth2 credentials AND (?) Register API Key?
How can I use client_id and other data that is in client_secrets.json? How can I use this client_secrets.json at all? Do I need download it, and how to use it?
Because when I saw sample code, for example this:
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context.getApplicationContext(), Arrays.asList(SCOPES));
credential.setSelectedAccountName(accountName);
YouTube youtube = new YouTube.Builder(new NetHttpTransport(),
new JacksonFactory(), credential).setApplicationName(context.getString(R.string.app_name)).build();
Or used AccountManager and get token
accountManager.getAuthToken(userAccount, "oauth2:" + mScope, null, (Activity) mContext,
new OnTokenAcquired(), null);
where mScope="https://gdata.youtube.com"
and then use it this way
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&maxResults=10&mine=true&key={here is my key}&access_token= ya29.bgJa5J8LHHu0Mu3P87mbPY9gfhSFzWUHh8gCw022FC6yfMO6GfVHveYr_BG1-HnWF-jpd-IDcGGVrF3gEf4UhSHPSrV76RAwqd4V17ixn72s1Xl6a0wQ4FVDz3cEZjUEN80o
I get the same authError error every time (in short):
"code": 401,
"message": "Invalid Credentials"
What I am doing wrong? How to use client_id in variant 1 and 2. Is it necessary? Because I think it is the reason why it does not work.
I am developing an android app. I was using a HttpURLConnection to get profile pictures of facebook users. The URL looks like this:
http://graph.facebook.com/?ids=username1,username2,username3&fields=picture&type=square
But now, since v2.2 doesn't let me to get profile pictures of users who are not using my facebook app, it throws an error:
{ "error": {
"message": "(#803) Cannot query users by their username (username1)",
"type": "OAuthException",
"code": 803 } }
I am not interested in using "Facebook SDK for Android". Let's say I use a pop-up webview to authorize my facebook app. What url would let me do the same thing? Is there a simple solution like this:
graph.facebook.com/?app=APP-ID&ids=username1,username2&fields=picture
Since v2.0 of the API, you are not supposed to use usernames at all - and that´s why you can´t query users by their username anymore. The only way to get access to data of a user is by authorizing that user and using the /me endpoint.
Main rule: Forget about users who did not authorize your App, you are not supposed to get any data of those for privacy reason.
I was working with twitter APIs and I am able to get specific user's timeline (tweets) without making the end user to login.
How can I do this in facebook? I don't want my user to login to facebook. I just need some feeds from users/pages which are publicly shared.
Does facebook allows this? How to do it? Any links
I don't know about Android but For Facebook API, I managed to get users / pages feed (public only) using the graph for a small project I was working on, this snippet might
help you
<?php
$pageContent = file_get_contents('https://graph.facebook.com/USER_ID/posts?fields=id,name&limit=1&access_token=ACCESS_TOKEN HERE');
// You can use your app token
$parsedJson = json_decode($pageContent); // decode JSON
echo $id = $parsedJson->data[0]->id; // this echos only the latest post ID
?>
So as you see, the code above requests Facebook graph and returns only post (latest one) from the user feed (because I limited it &limit=1) that code is working for me and might works for your needs