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

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.

Related

Getting post lists from facebook pages

I'm trying fetch list of post from given set of facebook pages using restfb(java)
List fbPages = Arrays.asList("178697151159/posts", "538560813021153/posts");
JsonObject fetchObjectsSubResults = client.fetchObjects(fbPages, JsonObject.class, Parameter.with("fields","shares,created_time"),Parameter.with("limit", 5));
But I'm getting a runtime error from facebook api as following.. IS there any body that can help me out to resolve this or is this impossible (
Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#803) Some of the aliases you requested do not exist: 178697151159/posts?,538560813021153/posts? (code 803, subcode null)
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1278)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1195)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1136)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:1058)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:1020)
at com.restfb.DefaultFacebookClient.fetchObjects(DefaultFacebookClient.java:476)
at main.main(main.java:75)
I suggest using 1 call per page. SO it should look like:
Connection<Post> postConnection = client.fetchConnection(pageId+ "/posts", Post.class, Parameter.with("fields","shares,created_time"), Parameter.with("limit","5"));
Depending on your use case, you can run over the postConnection with a for loop to get all posts or take the data from the first page of the result set with postConnection.getData().
In both cases you can eventually work with a Post type and access the fields your are interested in. The other fields are left null.
BTW working with multiple ids in a single call or request these ids one after another makes no difference to the Facebook calls. The amount that is internally calculated is the same; in your case 2.

How to retrieve graph impressions with string action types

I am sending a request for graph insights with the action type breakdown like this one given in an example on Facebook page : https://graph.facebook.com/XXXXXXXX/app_insights/story_publishes?since=1418112000&until=1426748400&summary=true&breakdowns[0]=client&breakdowns[1]=action_type&breakdowns[2]=auth_state&date_format=U
The result is however difficult to read because the type of action is represented by a numeric value (uuid) like this: "action_type"=>"465905580137487", so I dont know what it relates to- checkin, share or photo upload. Also for different apps those uuids are also different. Does anyone know what call I need to make to get the action type names as strings? Thanks for help
You need to call this URL:
https://graph.facebook.com/{action_id}
where action_id is the value returned by action_type. You'll receive the action details on the response.

Facebook Graph API event-id/comments?since=2014-02-01&until=2014-02-10 , Date filter has no effect

I am trying to bring comments made on a particular event by targeting this URL: https://graph.facebook.com/1466384840257158/comments
I am passing the user_access_token
I have two comments at present on this event made on the same
day(2014-03-29)
Now I try to pass a date which should bring an empty data result/object
like this: https://graph.facebook.com/1466384840257158/comments?since=2011-01-01&until=2014-01-10
This request has no effect, it still shows me the two comment made
on the 29th
I have tried the same kind of date range on my user-id/feed and it
gave me an empty data object.
Finally i tried event-id/feed (before trying date filter) and it
gave me the following error
.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
Could you please guide me about date filter on that particular query (point4) or if you have any other idea to use date filter on comments made for an event.
Comments use Cursor-based Pagination, so you cannot use since or until on the comments endpoint (these parameters would work f.ex. for the feed endpoint).
To get the comments in a time range you have to fetch all comments from NOW to the start of the time range, f.ex. with https://graph.facebook.com/1466384840257158/comments?filter=stream&limit=1000+paging (the filter=stream will order the result with the timestamp).
USING SINCE UNTIL FOR COMMENTS on GROUP
If you want to use since and until for comments, it is not possible directly for a group. So, First you can apply it for status(feed) and then get the comments for that feed.
This works for me:
{group_id}/?fields=feed.since(08/25/2016).until(08/31/2016){from,comments{from,message}}
Why don't you try first to filter by notifications?... notifications allows you to add parameters like since. For example (using Facebook pages):
https://graph.facebook.com/PAGEID?fields=notifications.since(2015-3-31 00:00:00).limit(250).include_read(true)&{id,created_time,updated_time,unread,object,link}&access_token=ACCESSTOKEN
Once you got the json data, loop through data, get the ID and send a second request but this time using the PAGEID_POSTID edge. Something like this:
https://graph.facebook.com/PAGEID_POSTID/comments?fields=id,from{name,id},message,can_remove,created_time&limit=1000
Voahla!... there's no need to read every comment!...
Note 1: A Page access token is required, along with the manage_pages permission
Note 2: Use the parameter/field include_read to get all the notifications, even the already readed
Note 3: In the second request, use the parameter/field "filter=stream" to order the posts and get the comments made in the name of your page
Note 4: Don't forget to control the asynchronicity once you loop!
Note 5: Notifications duplicate posts, use an array to avoid to read more than one time the postUse the parameter/field include_read to get all the notifications, even the already readed
I do not know if it's too late. But, Yeah it works in the graph api version 3.3.
for example: if you wanna get comments on a post of a Facebook page you can do it like this:
You have to use page Access-token
The get Graph Request : post_id/comments?since=some_date

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.