Localized hometown from facebook connect - facebook

When using facebook connect with devise, I get the hometown like this:
... hometown=#<Hashie::Mash id="116045151742857" name="Munich, Germany">
locale="de_DE" ...
Is there a way to get each users hometown in his own locale or at least in one set locale (de_DE in my case), e.g. "München, Deutschland" with the facebook API?
I don't want to sport my own database of hometowns if I don't have to.

Note tested, but you could try adding &locale=de_DE to the graph call. You can get the locale from the user object so potentally could customise this per user. Do a "/me" graph call to get the locale, then do a "/me?locale=de_DE" to get it in the user's language.
As I've said, I've not tested so it may not change the content of the field (e.g. Germany -> Allemande) but worth a shot if you've not tried it.

Related

How do I get the current User Id with GoViral ANE

I am using the GoViral ANE for integrating with Facebook, specifically creating a leaderboard to display in my game.
I would like to highlight the current user's score, but I don't appear to have access to the id that is returned via the APP_ID/scores request.
For example, data is returned in the following format:
{"score":123,"user":{"name":"Colin","id":"1234"}}
The id portion is what I am looking to match to the current user to highlight the score.
I have tried GoViral.goViral.getFbAccessToken() but this is clearly the wrong thing.
I have also tried making a call out to get the current user's score, but it also requires a User Id to make the call, so I am a little stumped on this one.
Searching on Google doesn't seem to return any useful results either.
Thank you for your time.
Ah, it seems I don't need a user id to make the call after all.
The call I was attempting was the following:
From the Facebook developer site:
You can read the score for a person playing your game by issuing a
HTTP GET request to /USER_ID/scores with a user access_token.
With this code:
GoViral.goViral.facebookGraphRequest(
GoViral.goViral.getFbAccessToken() + "/scores",
GVHttpMethod.GET);
However the following call works:
GoViral.goViral.facebookGraphRequest(
"me/scores",
GVHttpMethod.GET);
So using "me" works instead of the user id, which returns:
{"score":123,"user":{"name":"Colin","id":"1234"}}
Allowing me to access the user id.

Get username field in Facebook Graph API 2.0

The "old" Facebook Graph API had a "username" field which could be used to create a human-readable profile URL. My username for example is "sebastian.trug" which results in a Facebook profile URL http://www.facebook.com/sebastian.trug.
With Graph API 2.0 Facebook has removed the "username" field from the user data as retrieved from "/me".
Is there any way to get this data via the 2.0 API or is the "username" now being treated as a deprecated field?
Facebook got rid of the username because the username is one way of sending emails via Facebook.
For example, given the url http://www.facebook.com/sebastian.trug
the corresponding Facebook email would be sebastian.trug#facebook.com
which, if emailed, would be received to messages directly (if the message setting is set to public), otherwise to the other inbox.
The username field of the User object has been removed, and does not exist in Graph API v2.0. In v2.0 of the API is there is no way to get the FB username of a user.
Source: https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
"/me/username is no longer available."
#Simon Cross - It being deprecated is documented, yes. That is not the question, the question is how to get it and -furthermore- I wonder why Facebook has made such a terrible choice and removed the username. Hundreds of applications that rely on the username to create accounts on their service will be broken.
#user3596238 - You can stick with the V.1 API which will be around until the end of April 2015, by far not the best solution but Facebook might be irrelevant by then anyway.
https://developers.facebook.com/docs/apps/changelog
Solution: ask the user for a username besides the actual Facebook login? - In my opinion, that makes the Facebook login completely pointless anyway.
While the 2.0 SDK will not provide the username field any longer, it is quite easily scraped if you have the user id number (which you will likely be using to access the graph anyway).
The url facebook.com/<user id> will redirect to facebook.com/<username>, which can then be extracted however you like.
my approach is scrapping the username using nokogiri through the user profile.
kinda like this (in ruby):
html = RestClient.get("http://facebook.com/123123xxx)
doc = Nokogiri::HTML(html)
username = doc.css('head meta')[1].attributes["content"].value
One of the ways could be to access facebook.com/{userid} using cURL and then follow the redirect.
The page rediects to facebook.com/{username}
Inspired from #RifkiFauzi 's answer, here is my solution in pure Python
#get html of a page via pure python ref. https://stackoverflow.com/a/23565355/248616
import requests
r = requests.get('http://fb.com/%s' % FB_USER_ID) #open profile page of the facebook user
r.raise_for_status()
html = r.content
#search string with regex ref. https://stackoverflow.com/a/4667014/248616
import re
# m = re.search('meta http-equiv="refresh" content="0; URL=/([^?]+)\?', html)
m = re.search('a class="profileLink" href="([^"]+)"', html)
href = m.group(1) #will be https://www.facebook.com/$FB_USER_NAME on 201705.24
username = href.split('/')[-1]
print(href)
print(username)
https://graph.facebook.com/?id=100005908663675
Simply change id to whatever.

API call to retrieve all public information of Facebook user?

I know I can call each individual field via something like
/---ID----?fields=gender,languages,age_range,bio,birthday,education,email,hometown
Is there a quicker way than listing every single field?
It is ok if the user has most of these fields locked down with their privacy settings, I just want it to pull what is available.
just try:
https://graph.facebook.com/{{ username or uid }}?access_token={{access token goes here}}
Example:
https://graph.facebook.com/zuck?access_token=###
will give all the public information available for that user.

Getting interests and activities in user specific locale via Graph API

we are working on a mobile app that accesses facebook user data.
We want to get the users activities, interests and favorite books, music, etc. We are fetching these information via the Graph API but now we are facing the problem, that the returned interests are in english language.
That are the steps we are taking to fetch common interests:
1) Get access token
2) Call https: //graph.facebook.com/me/interests&access_token=XXX0&locale=de_DE
The response is somewhat like:
{"data":[{"name":"Programming","category":"Interesse","id":"101882226520576","created_time":"2011-08-02T08:38:03+0000"}]}
You can see, that the category is tanslated, but we are also looking for the german version of the name field ("Programmierung").
When i try to access the english "Programming"-page on http://www.facebook.com/pages/Programming/101882226520576 i am forwarded to http://www.facebook.com/pages/Programmieren/106375099398136.
Accessing 106375099398136 with Graph API yields the correct response:
{
"id": "106375099398136",
"name": "Programmieren",
"link": "http://www.facebook.com/pages/Programmieren/106375099398136",
"likes": 6983,
...
}
How do i get this locale dependent link between "Programming"-page and "Programmierung"-page via the Graph API?
just want to share a possible workaround for the above problem.
Basically we are emulating what is happening when the user trys to access a facebook page and is redirected to the localized counterpart. So we are sending a HTTP request to "facebook.com/pages/PAGE_ID" with the user locale set in the HTTP header and follow the redirects until the last location. The URL of the last location is somewhat like "http://www.facebook.com/pages/LOCALIZED_PAGE_NAME/PAGE_ID" and we are extracting the page name from this.
This is an effective but far from efficient solution :) Would appreciate a more elegant way to handle this.
Bye,
Tobias

Friends_interests/likes/etc return as blank from Facebook Graph API

I've been messing around with the graph API and have been able to access my own information just fine. However, when I attempt something like:
https://graph.facebook.com/999999/likes?access_token=xxx (where 999999 is a friend's ID)
I get a blank graph like so:
{
"data": [
]
}
Keep in mind I'm doing this all manually for the time being. This is the URL I used to request permission from my profile:
https://www.facebook.com/dialog/oauth?client_id=xxx&redirect_uri=http://www.google.com&scope=email,read_stream,offline_access,user_likes,friends_likes
It all works hunky-dory and I get my access code, yet I still receive the blank graph. Suggestions?
Thanks.
Have you tried multiple friends? Your friends can configure what information third party applications can have access to, of theirs. For example I could limit applications that you use to not see anything about me, if we were friends.
Also you could check in account --> privacy --> settings --> applications and see if your application in fact has the permissions you think you granted it as a user.
-Kevin
I agree with kevin. You need to request permissions first to get at the info and you also need to be prepared that you will get a blank list.
I suggest that you use an already built api as it will save you a lot of time. I've recently released one here that should get you going in no time at all.
The code looks like this:
Dim FB As New SessionInfo("[access_token]")
Dim Req = New Functions.Requests(FB)
Dim U = Req.GetUserInfo("[userid for friend]")
Response.Write(U.name)
Also you can get a list of friends by calling this
Dim FL = Req.GetFriends()
For Each F In FL
Response.Write(F.name)
Next
I have come to notice that even though an application can request (and be granted) certain permissions, e.g. to access Likes, it doesn't necessarily mean that an application will be able to access this information.
I'm not a 100% certain of this but there might be two instances where e.g. requesting a users Likes results in an empty data set even though the right permissions where requested and granted by the user:
The user has set custom permissions in his/her privacy settings
not make public the information (e.g. Likes). Basically, customized
permission settings overrule the granted permissions that an
application requested.
The user is under 18. https://www.facebook.com/help/?page=214189648617074