facebook query pages sort on likes - facebook

I am looking for a way to query facebook pages that for example, have something to do with food.
Not to difficult ;)
$pages = $facebook->api('search?q=food&type=page');
But... I want to get the largest pages (most likes) of that category. Search get's close, but I can't influence the return order (I think).
I have been looking here: https://developers.facebook.com/docs/reference/fql/page/
to see if I can get it to work with a query, but it seems I can only query information about a specific page.
I have been looking for several solutions without succes. Is this even possible at all? Any help would be much appreciated!

How about this:
Make that request to "search?q=food&type=page", then take the results and iterate over them.
For each result make the following FQL query:
SELECT
name, username, fan_count
FROM
page
WHERE
page_id="ITERATION_PAGE_ID"
For example, the first result I get has the id "25255939006", the FQL will be:
SELECT name, username, fan_count FROM page WHERE
page_id="25255939006"
And the result is:
{
"data": [
{
"name": "Food",
"username": "",
"fan_count": 146291
}
]
}
Hope this is what you were after.

Related

Facebook Post likes

I've a question in regards to the FB Graph API. Assuming I would like to search for the likes related to a Facebook post,I would have to do this:
541729512538864_792100727501740/likes/
But what If I would like to find whether a user(me) has liked that specific post(not page)?I've tried doing it this way.
541729512538864_792100727501740/likes/<my user id>
But it does not return any results.So what would would the actual Graph path be?I would gladly appreciate any help,thank you :D!
With the Graph API this is not possible imho. You'll need to use FQL instead:
select post_id, like_info.user_likes from stream where post_id="541729512538864_792100727501740"
will return
{
"data": [
{
"post_id": "541729512538864_792100727501740",
"like_info": {
"user_likes": false
}
}
]
}
in my case. This is always bound to the User of the Access Token you're using to running this query with. See https://developers.facebook.com/docs/reference/fql/stream/ for a reference.

Can't get facebook checkins, data array always empty

I have a strange behavior when trying to get the checkins of a place or user: the result is always an empty data array:
{
"data": [
]
}
This happens when I use the Graph Explorer: /4/checkins
or when I use FQL: SELECT checkin_id, author_uid, page_id, timestamp from checkin where page_id = 111856692159256
or when using javascript:
FB.api("/me/checkins", function(response){
console.log(response);
});
I always use an access_token, even ones with ALL permissions available. Simply no result.
I read, that checkins are now post with locations, so I tried /4/posts?with=location, but still no luck. Is there some kind of bug, or restriction (country/app-permissions) I am missing?
EDIT: I now got lucky and can get of SOME of my friends their checkins. It's like a 50/50 chance...
There are 2 differences commands, one command is the url to get the user checkins:
/me/checkins will return all checkins of the current user (the user that generate the token)
/<USERID>/checkins will return all checking from the User ID that the current user can see.
/<PLACEID>/checkins will return all friends of the current user that made checkin at this place
So, probably you have no friends that made checkins at the id 111856692159256

Facebook: identify object id and type by url

I want to get the id and type of a Facebook object based on its URL.
My goal is to identify if a certain URL is a Facebook Event (for example https://www.facebook.com/events/258629027581347).
So if I had the object-id of that object I could do the following FQL query and know that if I get a result the object is an Event:
select eid from event where eid = 258629027581347
The problem is getting the object-id based only on the URL. I do not want to parse the id from the URL because there is no guarantee that the format of the URL will remain the same in the future. I want to find a way to do it through one of Facebook's API's.
After searching for a while, I found the following suggestions for how to do this, but unfortunately none of them work:
FQL query from the object_url table - the query yields no results:
SELECT url, id, type, site FROM object_url WHERE url = "https://www.facebook.com/events/258629027581347"
Use the graph api:
https://graph.facebook.com/https://www.facebook.com/events/258629027581347
This returns a JSON object containing only the URL - no id.
Use the graph api with ?ids= like this:
https://graph.facebook.com/?ids=https://www.facebook.com/events/258629027581347
This returns the following JSON, also no id:
{
"https://www.facebook.com/events/258629027581347": {
"id": "https://www.facebook.com/events/258629027581347",
"metadata": {
"connections": {
"comments": "https://graph.facebook.com/https://www.facebook.com/events/258629027581347/comments?access_token=AAACEdEose0cBADzSuuyJWohIwkXuvQGJUsIlSJz04J4nzKqqQXTvGiPXf4YDBPuh0rdyXgSWnWcJpN3X3GaATVLjG6UmZBiHKmcxCWwZDZD"
},
"type": "link_stat"
}
}
}
What am I missing here?
Thanks!
To my knowledge, there isn't an API method at this time that takes a Facebook URL and tells you what it is. The only way to go about this is to parse the URL and look for the last element and pass this to https://graph.facebook.com/258629027581347?metadata=1&access_token=XXXX
It's a noble goal that you are trying to build a future-proof Facebook application, but I don't think that is a possibility at this time. The Facebook platform is still evolving. There is less of a guarantee that the api methods will remain constant than the url struture.

I am having problems running Facebook FQL queries that include long user ids

I am having problems running queries with FQL that include a supplied "Large"(beginning with 10000..) User ID
here is an example of one that is not working:
fql?q=SELECT uid, first_name,last_name,pic,pic_square,name
FROM user
WHERE uid=100002445083370
Is there a way to encapsulate the long number so it's passed as a string?
here is another example:
/fql?q=SELECT src_big
FROM photo
WHERE aid IN (SELECT aid
FROM album
WHERE owner=100002445083370 AND type="profile")
ORDER BY created DESC LIMIT 1
Has anyone been able to solve this issue? I am testing the queries in the graph explorer with no luck as well.
I see what the problem is,
The User id I am trying to pass is supposed to be: "100002445083367", but from querying the list of friends and grabbing their User Id, I am getting back "uid":1.0000244508337e+14 which is being shortened to: 100002445083370 (php removing the e+14) throwing off the second query. I need to make sure the id I am grabbing is staying as a string value not a number while I pass it back and forth from PHP and Javascript.
The problem is because of the way PHP handles JSON_DECODE. I had to modify Facebook PHP SDK and add a preg_replace previous to the json_decode. It will make sure json_decode doesn't convert large integers to floats by first converting them to strings.
here is the code:
line 803 from base_facebook.php:
$result = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $this->_oauthRequest($this->getUrl($domainKey, $path),$params)), true);
here is more information on the subject:
http://forum.developers.facebook.net/viewtopic.php?id=20846
What do you mean by "not working"?
That query works for me in Graph API explorer but the response is
{
"data": [
]
}
I think that user-id isn't valid; https://www.facebook.com/profile.php?id=100002445083370 gives a "Page not found" error for me.

Determine Object_ID of a URL to use with the Facebook Open Graph

I am trying to learn how to use the Facebook Open Graph API and have a question on how to determine the object_id of my site. I need this object_id so that I can do other queries, such as I want to get a list of users who have liked my site within a given time period.
Based on other Stackoverflow questions I have seen that I should be able to run this query to get the object_id
select id from object_url where url in ('www.bubbasgameroom.com', 'bubbasgameroom.com')
When I run that query it comes back with an empty result. When I run the following query, I see that my page has been liked 21 times
select total_count from link_stat where url in ('www.bubbasgameroom.com', 'bubbasgameroom.com')
What am I missing here? Any help will be greatly appreciated.
Thanks!
Most likely the url should be identical to the og:url meta tag if used on your website. Also you need to append the http:// part for it to work. For example this would work:
SELECT url,site,id
FROM object_url
WHERE url IN (
'http://developers.facebook.com',
'http://www.imdb.com/'
)
Result:
[
{
"url": "http://developers.facebook.com",
"site": "developers.facebook.com",
"id": 113167538713703
},
{
"url": "http://www.imdb.com/",
"site": "www.imdb.com",
"id": 6903354771
}
]
But this doesn't:
SELECT url,site,id
FROM object_url
WHERE url IN (
'developers.facebook.com',
'www.imdb.com/'
)