Programatically differentiate between facebook pages and profiles - facebook

I'm writing an app which requires me to determine whether I show the fb "like" button or not. fb profiles don't have "likes" but pages do. any recommendations on how I can programatically differentiate between a fb profile and a fb page? the only input i get from the user is the fb profile/page URL and based on that I need to determine whether its a page or a profile and then display the like button.
thx,

Yes, you can look at the type attribute of the returned JSON. For example, take a look at actual, redacted Graph API responses that I receive for a user and a page:
//This is JSON for a user
//Call to https://graph.facebook.com/123456789
{
"id": "123456789",
"name": "Sean Hill",
"first_name": "Sean",
"last_name": "Hill",
//more attributes
"type": "user" // <--- This one
}
vs
//This is JSON for a page
//Call to https://graph.facebook.com/thesolusean
{
"id": "323796444951",
"name": "Solusean",
"picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/50290_323796444951_3601170_s.jpg",
"link": "https://www.facebook.com/thesolusean",
"likes": 28,
// more attributes
"type": "page" // <---- This one
}
Without knowing which programming language you're using, this is the best answer I can give.

So far it seems the only quick way to know whether given profile is page or actual user is by looking at category attribute. If this attribute is present then its a page otherwise it could be user. FB reference docs doesn't seem to have any clear guidance (see https://developers.facebook.com/docs/graph-api/reference/profile). In additional most of the APIs that return profile as part of other response only includes partial information of id, name and category:
"from": {
"category": "Magazine",
"name": "Astronomy Magazine",
"id": "108218329601"
},
Note: I'm confused by #Sean Hill's answer. There is no type attribute in profile objects.

Related

Facebook post data has empty privacy field

We are having an issue with one facebook users account where the privacy field returned for his posts are always blank. I have tried reproducing this with my account or a test account, but in all cases the privacy is filled in. Here is a sample using the graph api tool (some fields removed for brevity):
{
"id": "<deleted_for_privacy>",
"from": {
"name": "Joe Blog",
"id": "<deleted_for_privacy>"
},
"story": "Joe Blog added a new photo.",
"picture": "<deleted_for_privacy>",
"link": "<deleted_for_privacy>",
"icon": "<deleted_for_privacy>",
"privacy": {
"value": ""
},
"type": "photo",
"status_type": "added_photos"
},
According to the documentation for privacy the field this should always contain a value.
My initial thoughts was it was related to the blackberry app being used and the old mobile version setting, but posting from the desktop browser results in the same issue.
So what does a blank setting mean? Is it public, private or a bug?
Not sure this is your case, but if the user is posting to a page, event, group or another users's feed, the privacy field is expected to be empty.
See the first note here (not the official fb doc page, I know):
http://api-portal.anypoint.mulesoft.com/facebook/api/facebook-graph-api/docs/reference/privacy-parameter
This is by design. You require a page access token or admin user
access token to retrieve this field.
Source: https://developers.facebook.com/bugs/300329193480725/?comment_id=345320875630426

Facebook: Link Request's sender to it's recipient?

When using the requests dialog, facebook issues a notification like this:
What I'm looking to achieve is for the user to click the request link shown above and to present a "Random User invited you to..." message on our App.
However, when clicking that link Facebook doesn't seem to pass through the id of "Random User" to the App. The url accessed by the link looks something like:
http://apps.facebook.com/randomcomp/?fb_source=notification&request_ids=350578327437399,350578327437399&ref=notif&app_request_type=user_to_user&notif_t=app_request
which doesn't contain any reference to the user who initiated the request.
From the App's side, there doesn't seem to be a way to get this information from Facebook. Sure, you can get a list of requests, but that list can contain information for many requests, including requests from other users in addition to the one we're interested in, so it's not useful in this case. For example, here's a snapshot of data:
{
"data": [
{
"id": "340083146057323_100003817986566",
"application": {
"name": "Random Competition",
"namespace": "randomcomp",
"id": "350578327437399"
},
"to": {
"name": "Hannah Smith",
"id": "100003817986566"
},
"from": {
"name": "Random User",
"id": "100002286042525"
},
"data": "100002286042525",
"message": "Use the app!",
"created_time": "2012-05-14T13:26:30+0000"
}, {
"id": "358318457550141_100003817986566",
"application": {
"name": "Random Competition",
"namespace": "randomcomp",
"id": "350578327437399"
},
"to": {
"name": "Hannah Smith",
"id": "100003817986566"
},
"from": {
"name": "Jane Young",
"id": "100003771838663"
},
"data": "100002286042525",
"message": "Use the app!",
"created_time": "2012-05-14T10:54:25+0000"
}],
}
}
As you can see, the data is being passed in, but there's still no way to join the click from the link mentioned above (for Random User) to the correct request in the list; the link passes through the ID for both requests, not just the one for Random User, and while the link states "Random User" it doesn't pass through an identifier.
Am I missing something? Is there a mechanism that isn't in the docs that will allow me to pick-up the "Random User" id so I can provide a nice "Random User invited you to..." message in the App when they click through?
Edit:
Turns out that this isn't possible - see my answer.
You can add some data to the request so that when you process the request you can differentiate that from other requests.
The data can be sent with app requests and users requests and the parameter name is "data".
For example, in the guide for the Requests Dialog you can see it in the properties table at the (almost) end of the document, it says:
Optional, additional data you may pass for tracking. This will be
stored as part of the request objects created. The maximum length is
255 characters
There's also some info about it in the Social Channels documentation, and a sample of (php) usage in the official blog post about Upgrade to Requests 2.0.
I hope that this is what you're looking for.
Edit
When you send the request you know who is sending it right? It's the logged in user, and so you can put the user id/name/etc in the data parameter of the request.
Then, when someone clicks on a request, get the request by the id that facebook passes to you, and from the data extract the user id of the sender.
As the documentation states, you have 255 characters to use, and with that you can do what ever you want, you can even serialize an object to that parameter and deserialize it later.
As it turns out, this is in fact not possible at all.
The link, as shown in the image below, can present multiple users:
which is why multiple request IDs are passed in, and the sender's ID isn't.

Facebook – Does a page exist for this URL?

I'm making a webpage/SEO checking page, where I can put in a URL and it will tell me various facts about the page.
I'd like to be able to tell if there is a Facebook page associated with the URL. Is this possible using the API, or by other means?
For instance, https://www.facebook.com/focalstrategy links to http://www.focalstrategy.com/ on the info tab – is there a way to go the other way and enter the URL and find the page(s)?
(Bonus points – anyone know of a way to do the same for Twitter accounts)
I don't think this is possible. Using the API, you can retrieve info about the url:
http://graph.facebook.com/?id=http://www.focalstrategy.com/
Would return:
{
"id": "http://www.focalstrategy.com/",
"shares": 38
}
Now I'm note sure if using the Open Graph Meta Tags would help return more data (still not what you need), but here is my website info without trailing slash:
http://graph.facebook.com/?id=http://www.masteringapi.com
Would return:
{
"id": "109784969102047",
"name": "MasteringAPI.com",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/276619_109784969102047_474156823_s.jpg",
"link": "http://www.masteringapi.com/",
"likes": 25,
"category": "Website",
"website": "http://www.masteringapi.com",
"description": "Master Facebook, Google and Twitter APIs! Learn Facebook Application Development Now!",
"can_post": true
}

Why I got so many posts without any content from Graph API?

I am developing a social media monitoring service. And I'm now trying to fetch the posts and comments from a certain group of users.
However, I found that a lot of empty posts are fetched by Graph API https://graph.facebook.com/somebodysuid/posts?access_token=xxxx . That is, a lot of posts are of the following form:
`{
"id": "somebodysuid_xxxxxxxxxxxx",
"from": {
"name": "XXX YYY AAA",
"id": "somebodysuid"
},
"type": "status",
"created_time": "2011-08-03T05:49:11+0000",
"updated_time": "2011-08-03T05:49:11+0000",
"comments": {
"count": 0
}
},
{
"id": "somebodysuid_yyyyyyyyyyyyyyy",
"from": {
"name": "XXX YYY AAA",
"id": "somebodysuid"
},
"type": "status",
"created_time": "2011-07-24T23:31:35+0000",
"updated_time": "2011-07-24T23:31:35+0000",
"comments": {
"count": 0
}
},
Through these are indeed posts, but they're totally useless. The worst thing is, half of the data I fetched are of this kind....
Can somebody please explain why so many empty posts would the API fetch? Can this be solve by any way?
Those posts are probably updates made through the "new share form" where users can tag places and friends and attach geo-locations without adding any additional message.
Those type of posts are typed as "status" but graph api does not return the other meta-datas yet (location, tags, etc...) that's why you see them empty.
Let's hope FB will fix that quickly :(
I think FB has started to add activity information that appears on a Facebook web page, such as "John Doe is now friends with Tom Jones", or "Fred Smith and 2 others have changed their profile image". This activity information is a) incomplete in the returned feed and b) does odd things when you look for more information by asking the graph API for detail based on the posts id field.
My current guess is that this is new functionality for the feed - I have been unable to find documentation or mention of it. They are very difficult to process at this time, since they look like other things and contain no identifying detail.
Here is the question I posted looking for help. It give another example:
Facebook graph "user/home" feed now contains activities as post items that are difficult to identify

Scope of Facebook API

I am trying to learn and create a Facebook API on the go. However, I haven't found any page on the developer pages that specifies the scope of the Facebook API in great detail. I understand public information can be accessed using Graph API. But at the same time understand that further access is possible, not sure how much though.
Is there anyway to access the 'Edit news feed options' of a user that authorizes an application?
I don't really understand what you mean by "scope", but the Graph API is not more than a series of URLs to contact the facebook servers with queries and obtain answers in form of JSON objects.
You can start learning by looking at the reference for the API here:
http://developers.facebook.com/docs/reference/api/
There are unofficial APIs for every language you can imagine, for example java: http://code.google.com/p/facebook-java-api/ , c#: http://facebooksdk.codeplex.com/ , etc.
To read the news feed, you can access it by:
https://graph.facebook.com/me/home?access_token=TOKEN (where TOKEN is the access token)
Fb will respond with a JSON object similar to the one pasted below.
{
"data": [
{
"id": "11111_1111111111,
"from": {
"name": "Name",
"id": "11111111"
},
"message": "SOME_MESSAGE",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/111111/posts/11111"
},
{
"name": "Like",
"link": "http://www.facebook.com/11111/posts/11111"
}
],
"type": "status",
"created_time": "2011-04-20T20:19:04+0000",
"updated_time": "2011-04-20T20:19:04+0000"
},
etc etc etc
],
"paging": {
"previous": "https://graph.facebook.com/me/home?access_token=TOKEN",
"next": "https://graph.facebook.com/me/home?access_token=TOKEN"
}
}
Having that, you can use the ID for the person or the message to perform new queries, as explained in the FB API page:
All of the objects in the Facebook
social graph are connected to each
other via relationships. Bret Taylor
is a fan of the Coca-Cola page, and
Bret Taylor and Arjun Banker are
friends. We call those relationships
connections in our API. You can
examine the connections between
objects using the URL structure
https://graph.facebook.com/ID/CONNECTION_TYPE.
The connections supported for people
and pages include:
Almost every information on FB is accessible through the Graph API, provided the user authorized the app with the rigth permissions:
http://developers.facebook.com/docs/authentication/permissions/