Tracking Facebook shares of a range of links - facebook

I'm looking to track shares of a range of links of my site. There are two tricky things here, though:
For one, the links could span multiple domains (so using the FB.ui share dialog and tracking the callback is out).
Second, links are specific to users for my site
So, an example url might be http://example.com/share/unique-id-goes-here
I know there's a Graph API query parameter (?id) but that'd only track one of the URLs and I'd like to avoid sending (potentially) hundreds of requests at the API all at once to get back sharing info.
Is there anyway to do a wildcard search? I'm open to other suggestions as well!

There is no way to do a wildcard search and no such option exists in the documentation. Your best bet is to look into Facebook Insights and attach ref params for links that you own.
Your second option is correcting this statement
I know there's a Graph API query parameter (?id) but that'd only track one of the URLs
You can track more than one id with the ids param
https://graph.facebook.com/?ids=http://www.stackoverflow.com,https://www.youtube.com
Response
{
"http://www.stackoverflow.com": {
"id": "http://www.stackoverflow.com",
"shares": 27967,
"comments": 4
},
"https://www.youtube.com": {
"id": "https://www.youtube.com",
"shares": 8709432,
"comments": 9
}
}

Related

Why is the Graph API for querying a group URL simply returning the group ID?

When I GET /{group-id}?fields=link I get just get back {group-id}, rather than a full URL like in the case of /{album-id}?fields=link, /{photo-id}?fields=link, etc. Sample request and response for a group:
GET /v2.5/1685218945065439?fields=link
{
"id": "1685218945065439"
}
whereas an album looks like this:
GET /v2.5/1685219628398704?fields=link
{
"link": "https://www.facebook.com/media/set/?set=oa.1685219628398704&type=1",
"id": "1685219628398704"
}
According to the docs link is a valid field on the Group object. I'm using a token that has user_managed_groups. I see the same result when querying OPEN and CLOSED groups.
Just looking at the URLs of my groups by loading them in my web browser, I see that they all use the format https://www.facebook.com/groups/{group-id}/, so it's easy enough to build a URL from the {group-id}, but is that URL format something I can actually count on?
Using Graph API v2.5.
This is a field that is kept around for historical reasons. Back in the day you were able to actually set a website for a group, for example https://example.com.
This functionality has since been removed from the UI on facebook.com but the field in the API is present as older groups might have this value set, but newer groups won't have it anymore.
There has been a bug report about this as well which has been closed as 'By Design' for the reasons mentioned above https://developers.facebook.com/bugs/1495489670770155/
I filed a bug report to which the Facebook team responded that this is the intended behavior (also noted by Bjorn in his answer). See Bjorn's answer for more details.
The good news is that, according to the Facebook dev on that bug report, the format of the Group URL will always be https://www.facebook.com/groups/GROUP_ID, so there's really no need to query the API for the Group URL anyways.

Issue when trying to requery on postID using facebook graph

Forgive me I'm new to the Facebook graph concept. I've read through the documentation and am a little lost on something that I want to try and do. I have been able to query posts based on a keyword such as "sailing" like so:
http://graph.facebook.com/search?q=sailing&type=post
I see that it returns a result set containing 25 of the most recent posts with the keyword provided. My issue comes when I try to take a post id and query it directly. What I want to do is to be able to take a post id and query it after a 24hr time frame to see if it has received any comments and to see how many likes it has gained since being posted.
I can take the userID_postID and query like:
http://www.facebook.com/userID/posts/postID
I can see the post with the likes but when I try this in the graph:
http://graph.facebook.com/userID/posts/postID
I get the following error message:
{
"error":
{
"message": "Unknown path components: / postID",
"type": "OAuthException",
"code": 2500
}
}
I've seen where people have commented that if you want to access a post you will need to get an access_token. I'm not sure why you need an access_token to access a post that you originally obtained without one. It doesn't seem to make sense. One thing that I have noticed when trying to do this with different posts is that this seems to be related to accessing posts of an individual rather than a fan page. Whereas a public page such as a fan page seems to return the results.
I also tried querying like:
http://graph.facebook.com/userID_postID/likes
this returns the likes for a public page such as a fan page but doesn't return anything for an individual page. Can anyone help point me in the right direction or maybe give me some explanation on what the proper way to handle this would be? Requesting an access_token from the user is something I do not want to do, this is mainly for a service that we're trying to create that allows us to survey based on a keyword. Any help would be much appreciated, thanks.

Convert any facebook URL into a graph ID

Is there a simple, reliable and potentially future-proof way to extract a graph ID from the API given any facebook URL? By "any facebook URL" I mean the URL for a personal profile, page, group, etc. All these things have various formats so I imagine there must be something in the graph API to definitively convert a facebook URL into an ID, right?
No, there isn't a way to do this simply within the API. You will need a set of pattern matching to match the various types of urls to extract either the id (album,note,photo,status) or username.
For example
Photos
facebook.com/photo.php?fbid=10100213582161431&set=p.10100213582161431&type=1&theater
https://graph.facebook.com/10100213582161431
Posts
facebook.com/zuck/posts/10100210345757211
https://graph.facebook.com/10100210345757211
Pages
facebook.com/pages/Joel-Spolsky/106083232757300
graph.facebook.com/106083232757300
Videos
facebook.com/video/video.php?v=10150398154330484
graph.facebook.com/0150398154330484
Events
facebook.com/events/138745136241434/
etc ...
Then it gets further complicated that even if you were able to get a silver bullet function that handles all these links your app would need to grant access to numerous permissions in order to access certain objects.
You may be able to get away with most links that have the id at the end but not all. So you can maybe use a regular expression catching links that end in numeric characters.
There is! You are looking for the object_url table, which you can query using FQL or directly with a request. See here: http://developers.facebook.com/docs/reference/fql/object_url/
EDIT:
You can also do this, but obviously less optimal:
function getObjectByUrl(url, cb) {
FB.api("/" + url.replace(/^.*?www.facebook.com/, ""), cb);
}

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

In the Facebook API, how can I retrieve the source object from a notification object?

Since notifications are not available in the Facebook Graph API, I am using FQL to retrieve them, as detailed at https://developers.facebook.com/docs/reference/fql/notification/.
What I would like to do is use the information returned to fetch the "source object". So if the notification is "Bob commented on your status", I want to find that status object - and if Bob comments on my Note, or posts to the Wall for my Event, etc.
notification_id, sender_id and recipient_id alone don't seem to be enough information to achieve this. The href field is tantalisingly close - it'll return a link that a user can click on to be taken to the appropriate page, but that doesn't look like much help to me as the URL format varies wildly between "source object" types. I can't find a reliable way to turn href into a parameter I can pass to the Graph API.
So, if what I want to do is possible, what's the best way to do it?
My thoughts:
Is there a way to give the "user-friendly" href to an API and have it return the appropriate Graph API results (or have it return the appropriate Graph API URL)?
Is there another way the information returned by an FQL 'notification' query can be used or combined to make a proper Graph API URL?
Is there another way of retrieving notifications that will give me what I want?
I'm using PHP and Facebook's PHP SDK, though this doesn't look like a PHP-specific issue.
Thanks in advance!
You can get object_id, object_type from the notification table and use that to fetch the original post. Sorry, this wasn't documented in the 'notification' table, but is documented now.
E.g.:
select object_id, object_type from notification where recipient_id=<user_uid>
which returns something like:
[
{
"object_id": "<object_id_1>",
"object_type": "group"
},
{
"object_id": "<object_id_2",
"object_type": "stream"
},
]
and you can then use the object_id to fetch the post:
https://graph.facebook.com/<object_id_1>?access_token=<access_token>