Can't display Facebook user avatar with Facebook API and Graph - facebook

I'm working in a React-Native app, and I'm also allowing users to login using FBSDK.
There seems to be an issue at the moment when trying to get the profile picture URL.
There are also several reports of this, like this one but still, after a year doesn't seem to be solved.
Attempted many ways but none worked, it always tries to download the file, seems it's missing the mime-type according to what the browser says.
The URL it gives is the following:
https://platform-lookaside.fbsbx.com/platform/profilepic/?asid={{myfbid}}&height=50&width=50&ext=1583348357&hash=AeTnFpMVwBXgFy_J
Also tried using the graph url directly: http://graph.facebook.com/{myid}/picture
And if I add the &redirect=false, it returns a data object with the platform-lookaside URL.
Everything I try, it tries to download.
This is how I'm currently trying to get the image using Graph API.
new GraphRequestManager().addRequest(new GraphRequest(
'/me',
{
accessToken: fbToken,
parameters: {
fields: {
string: 'picture.type(large)'
}
}
},
graphRequestCallback
)).start();
It works, but the URL is the same.
Any idea on how can I solve this? I might be missing something or the bug is still happening?

If you just change the graph url (http://graph.facebook.com/{myid}/picture) from http to https, it should work for you. Not sure if that's a new fix in React Native or not, but that solved it for me.

Related

Facebook OAuth SSO Issue

I have a JavaEE Application. I am trying to implement OAuth.
But I am facing some strange issues:
As per the documentation to manually building the sign in web flow I have to provide a link like this https://www.facebook.com/dialog/oauth?client_id=1231298371123&display=popup&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fc%2Fportal%2Fauth%2Ffacebook_login%3F&scope=email,public_profile,user_birthday&response_type=code%20token which will open the dialog. But the dialog is not opening.
And when the SSO is successful FB is redirecting to the url given above but the problem is FB is appending the query strings like state, code, etc with #. Something like: http://localhost:8080/c/portal/auth/facebook_login?#state=ASDASDASDASD&access_token=EAANXZAlBTi........ Because for this I cannot get the parameters in Java.
Do any one came across this kind of issue.
Please help.
Not sure if I understood the question right but if you want to read the string after # you can use the following code
URI uri = new URI("http://test.com/#something=some");
String fragment = uri.getFragment();
fragment will be everything after #

Fitbit OAuth 2.0 and Unity Project (RestSharp as well)

I've been trying to get OAuth 2.0 to work correctly. I have managed to make the url that that will do the "deny/allow" for my app by opening a webpage with just
Application.OpenUrl(uri.ToString());
The problem is that I have no idea how to get the redirect and the auth token from the page if the user hits allow. When you hit allow, right now nothing happens it just sits on the page. Checking Networking in chrome debug does have the redirect and token there but it never actually sends it..
I was recommended to use RestSharp but I again have no idea how to use it with Unity as there are lot of resources for Android/iOS PC etc. but I can't get any of them to work for this Unity project...
var client = new RestClient("https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=*clientID*&redirect_uri=http%3A%2F%2FfitRPGcallback&scope=activity%20profile%20sleep%20social");
Debug.Log("client made");
var request = new RestRequest(Method.POST);
request.Resource = ("profile%20sleep%20social");
client.ExecuteAsync(request, response => { Debug.Log("response is : " + response.Content);});
Application.OpenURL(client.BaseUrl.ToString());
In the URL I do have the correct clientID in there as well just not sure what I can and can't show for security reasons etc.
Biggest problem is just having no idea how to get the return value from the webpage after the user hits allow/deny...
Any insights would be super super appreciated cause I just want to start making the actual game but there's not as much point if I can't get this data...
So, I'm posting on a few other applicable questions as well since I have finally figured out my answer.
Unfortunately I'm not using REST so that part is still up in the air BUT I did get it to work with just Fitbit, Unity and a Webview plugin (you will need a webview OR a way to get the initial code back from your first OAuth2 call)
You can find steps here.
http://technicalartistry.blogspot.nl/2015/07/oauth2-unity-and-month-of-cursing.html
EDIT:
So I had to change how I did it because Fitbit changed their ToS where we are no longer allowed to use Webview based Authenticators (which is what I was using in the above blogpost.)
Give this next post a look for how to make an Android Plugin that will grab the Accesstoken from Fitbit's OAuth. This is a FREE way to do it since you make it yourself and it's ezmode :)
http://technicalartistry.blogspot.ca/2016/01/fitbit-unity-oauth-2-and-native.html

Facebook graph api function - empty response

im currently working on facebook integration into my mobile AS3 game. I'am downloading friends pictures, which works just fine and is not currently an issue. Problem is, i am trying to detect, if user has silhouette (default) picture or his own (is_silhouette property);
Here goes code:
(response[i].id) is valid user id which i have got from previous api comunication
...
HasDefault(response[i].id);
...
private function HasDefault(uid:int):void{
FacebookMobile.api("/"+uid+"/picture", callbackX);
}
private function callbackX(response:Object,fail:Object):void{
if (response != null){
trace(response.url);
trace(response.is_silhouette);
}else{
trace("here goes nothing...");
}
first things first...this code above has 2 issues. First problem is, unless i use absolute URL, facebook does not respond, so API method has actually look like this:
FacebookMobile.api("https://graph.facebook.com/"+uid+"/picture", callbackX);
i dont know why i have to use absolute url here, because anywhere else id/function is good enough...but that is not still main problem.
If i use absolute URL i do get valid response from facebook but according to this https://developers.facebook.com/docs/reference/api/using-pictures/ i should get response.url and response.is_silhouette in my response object. i however recieve only empty response object...I'am starting to be realy desperate.
In addition, i have tried to paste THE SAME request into the https://developers.facebook.com/tools/explorer explorer and surprise surprise...it returns
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc1/somenumbers.jpg",
"is_silhouette": false
}
}
...which is exactly what i need...but within the application i get only empty response object...
I do not know what you line "FacebookMobile.api("https://graph.facebook.com/"+uid+"/picture", callbackX);" does.
But whatever library that is, stop using it, because its not letting you specify the call you want to make. You can just call the graph api calls yourself using a URLLoader.
So here is the magical thing that is going wrong: You need to be able to append an extra variable when you request the picture: "?redirect=false"
This tells facebook to give you a json response. If you do not have that variable, you will get a redirect to the actual image, which is usually what a person wants anyway.
To see how that works, test out the two links below, one with redirect=false - which you want. and One with it set to true - which you do not.
https://graph.facebook.com/shaverm/picture?redirect=false
https://graph.facebook.com/shaverm/picture?redirect=true
I am pretty sure what is happening is that you are getting the image back instead of the json response describing the image.

Open Graph & Rails not retrieving object's URL

I'm using Rails to try and add an action for an object both defined for my app on the open graph. I am using an :after_filter in my controller to call the following after session#create:
#graph.put_connections('me', 'workkout:complete', :session => url_for([#plan, #session]))
I am getting the following back from Facebook:
{"error":{"type":"Exception","message":"Could not retrieve data from URL.","code":1660002}}
I have checked that the correct URL is passed to put_connections, and when I visit this URL using Facebook's Lint tool, everything is correct.
I can't understand why this isn't working, my only thought is that Facebook is hitting the URL moments before rails has generated the object? - not sure if that's even possible though.
Can anyone shed any light on this?
Turns out it was because the create action and the put_connection methods take place in independent threads and as such the URL is not ready when put_connections is called. Solution here http://railscasts.com/episodes/363-facebook-open-graph?autoplay=true

Codeigniter Facebook app POST method AND query_string

I have a toy facebook app I'm playing with so I can understand how it all works. It's fine if you go the the app like this: http://apps.facebook.com/pushup-challenge/ (and connect it). But if you then go to it from your facebook page, FB uses the URL http://apps.facebook.com/pushup-challenge/?ref=bookmarks.
In my log file, I see that FB is POSTing the data and including the /?ref=bookmarks to it's call to my codeigniter system. This is causing it to either say "invalid URI parameters" or give me a 404, depending on if I've edited the system/core/URI.php file to add rawurlencode() to a particular call.
I've tried using mod_rewrite to get rid of the query_string, too, but since it's POSTing, it doesn't appear to be working (though I'm not exactly sure why).
Has anyone else run into this? How did you fix it?
Thanks in advance,
Hans
try $config['uri_protocol'] = “PATH_INFO”; and set enable_query_strings = TRUE
or
set
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?=';
in config.php
Because it isn't calling your file by name (just ?ref=bookmarks) the server runs thru the standard default files: index.htm, index.html, index.asp. Because you need to accept a POST, you need a server that allows POSTs to htm & html if you choose to use those. Index.asp will accept POSTs on most servers, and that works for me.
SOLUTION: Add a file (index.asp), that calls the real app that you named in the App settings.