Get names from Graph API if the ID provided is a non-friend? - facebook

I am building a turn-based game and would like to allow players to play games against other users in the database that are not their friends. Currently I am only storing FB ids from which I am providing a mixed list of friends and non-friends to select from. I have a call to retrieve pictures and names from the FB API but only picture urls are being returned for non-friends. Is there another way to get names from FB API or do I need to store names in my database?

As outline in Graph API User Section, you can make a call to the Graph API and get the information (User's name) that you need.
This is an excerpt from that page which is relevant to your requirement:
You can choose the fields you want returned using the fields query
parameter:
https://graph.facebook.com/me?fields=id,name
Modify the above API call like this:
https://graph.facebook.com/THE_USER_ID?fields=name, picture
Also of importance is in the Fields table listed on the page linked above. To get the User's Name, No access_token required
Now, you haven't tagged the platform you are working on, so I cannot give you the actual code. I work on Android and am not familiar with other platforms. But the Graph API call will essentially remain the same.
Once you have the User's name and Profile Picture, then you can store in your Database if you so desire.

You should be able to get a JSON object with the name, username, id and photo of any user without an access_token by making a call to:
http://graph.facebook.com/USERNAME_OR_ID

Related

Get Facebook user work

I'm trying to write some application that scan user's group posts. When I read the group feed posts using the API I’m interested to get some information on the one who posted this post ('from' field). The graph API today gives only the id and the name of this person. I'm interested also in his work place. I tried taking the user id and to access the / resource and to get his work field , but this field is not returned. When I’m looking on the same user profile in Facebook I see his work place is public, even I’m not connected with him.
Anything I can do to get this user work with the existing Facebook API?
Normally, if the work history info is not public, you'll need the "user_work_history" permission (see https://developers.facebook.com/docs/facebook-login/permissions#reference-extended-profile).
If it's public, you can try calling the
/{USER_ID}?fields=id,work

Seemingly missing information from Facebook's Graph API

Consider the following:
Friend with ID 1 is in a relationship and has his birthday data filled in as well
Friend with ID 2 is also in a relationship and has his birthday data filled in too
Both of users with ID 1 and 2 are friends and if I login to Facebook, I can see the above mentioned information without any problem.
Then I make a call to the Graph API using the Facebook SDK, so I make something similar to:
$this->_facebook->api("/1");
For this ID, in the returned array I can see the relationship status, the birthday etc.
However
$this->_facebook->api("/2");
does not return this information, only the absolute basics such as 'name', 'id' and 'gender' - I'm using a simple print_r() statment to dump the returned array. When initiating the login I send the right permissions via the 'scope' parameter (and hence I can see the information belonging to user with ID 1).
So the question is: If I see the birthday and rel status for both users on the interface, why I only see one via the api calls?
I'm assuming in your example there, that user '1' uses your app or is a friend of a user of your app (assuming you have the appropriate friends_* permission)?
Other users' information won't be available via the API - even if you can infer that information through other pieces of data you have access to - in general you can only access data on behalf of your app's users and their friends, and privacy settings can override what you can access about your users' friends, even if your user can see the info on facebook.com

User Created Open Graph Objects in Facebook App

I'm trying to build a Facebook App that will run in the Canvas on Facebook. I want to give users the ability to create custom open graph objects. For example I want users to be able to make a donation bucket. Title, Description, amount needed, time left, goal. I want the user to make these and then when someone contributes it will post saying "USER_NAME added to the donation TITLE"
Is it possible for users to create objects in this way? Most of what I've seen is about the developer making objects and users acting on them.
An Open Graph object is basically just an URL, that provides the relevant info via appropriate meta elements.
So where’s the problem? You just provide an URL that provides the data your user entered – this could f.e. just contain an id as GET parameter, which let’s your script read the relevant data out of your database and fill the meta elements with it.

How to get facebook friends list with hometown using Graph API?

I know you can get friends list using this url:
https://graph.facebook.com/me/friends?access_token=XXX
But what I see there is a list of friends with ids and names, but I need hometown on this list. I requested friends_hometown permission, and when I run this url:
https://graph.facebook.com/100001986459077?access_token=XXX
then it works ok - I see hometown among all the fields.
But I don't want to call second URL for all the friends (too many times). I would like to get it in one call using first URL. Is there a way to achieve this target?
Notice: I'm not interested in FQL solution as I know it. All I need is graph API valid url to perform this action.
https://graph.facebook.com/me/friends?fields=id,name,hometown,location&access_token=[access_token_here] will provide you with the list you're wanting.
You will need to ensure the scope for the access token includes the friend's location and hometown in order to retrieve the data for that user's friend data.

How to retrieve user's Lived places, Trips and Life Events from Facebook Graph API?

Users can add "Lived places", "Trips" and "Life Events" on a Map on the new Timeline.
As you can get user's checkins via Graph API, I was wondering if it's possible to retrieve those locations as well?
According to the Facebook's Graph API Explorer and documentation this is not currently implemented as a GET possibility in the Graph API.
However, with the appropriate access token, you can retrieve certain aspects of a profile that include a Location ID that can be used to find the Location on Facebook, which you can then retrieve the Address, City, State, Coordinates, etc.
So, all around, the answer is no, at this time, you cannot retrieve Map information with Graph API. Hopefully, Facebook will make this available in the future.
ETA: I just just reviewed the Facebook OAuth Scope List and did some trial and error with the Graph API Explorer. I discovered the following...
While there is a permission scope for "user_location_posts" that must be included in the access token in order to get the location posts (i.e. statuses with a "Place" section) to show up in the feed/posts return from the appropriate GET call, there is no way to only retrieve the posts defined as "user_location_posts." In order to retrieve posts at all, you must first have the "read_stream" or "export_stream" permission which returns everything, not just the location posts.
You're going to need permissions to get the rest of the profile to find the locations on their photos, videos, and any other components that could potentially have a location attached.
There is a strong possibility that there is a Facebook component called "locations". Currently, it returns the GET error "(#100) Subject must be a part of the whitelist" rather than the typical error of "component does not exist". Therefore, it's possible that it's there and that the public does not have access to it at this time. It's also possible that this is just a bug I found.