Facebook: identify object id and type by url - facebook

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.

Related

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 Real-Time updates: comment on post vs comment on album

Status entry comment:
{"object":"page","entry":[{"id":"106182246249179","time":1386582683,"changes":[{"field":"feed","value":{"item":"comment","verb":"add","comment_id":"185457974988272_294727","parent_id":185457974988272,"sender_id":106182246249179,"created_time":1386582683}}]}]}
Album comment:
{"object":"page","entry":[{"id":"106182246249179","time":1386581446,"changes":[{"field":"feed","value":{"item":"comment","verb":"add","comment_id":"185444231656313_190183","parent_id":185444231656313,"sender_id":100006218707108,"created_time":1386581446}}]}]}
They seem impossible to distinguish. However, the first one's real post id is pageid_parentid = 106182246249179_185457974988272. If you try to do the same thing with the album comment to get the feed from the stream FQL table, you won't get anything (or an exception with graph api).
Has anyone found a way to distinguish somehow between the two?
Yes.
First you need the object_id
object_id=pageid_parentid
Make this api call with the object id:
GET https://graph.facebook.com/v2.9/{object-id}?fields=type,status_type&access_token=token
The response should look something like this if the parent is a post:
{
"type": "status",
"id": "106182246249179_185457974988272"
}
If it's an album, it will look like this:
{
"type": "photo",
"id": "106182246249179_185457974988272"
}

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

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.

Facebook - obtain location /places ID via location name

I'm able to return a location's details by sending a query via the graph api with the location's ID, however I'm looking to achieve the reverse - effectively find location id by sending a request containing the location name (city, state etc). Is this possible?
This is possible under a few different approaches. You can either search using long / lat positions and put the place name into the query. This search will search places only.
Do the following
https://graph.facebook.com/search?q=ritual&type=place&center=37.76,-122.427&distance=1000&access_token=mytoken.
This will return ritual coffee.
Another way is to search through facebook pages using the following
https://graph.facebook.com/search?q=ritual%20coffee&type=page&access_token=mytoken
This way is more difficult as you will obviously need to parse the list in more detail.
You also can use the place sdk from facebook:
compile group: 'com.facebook.android', name: 'facebook-places', version: '4.30.0' // For latest version, see https://developers.facebook.com/docs/android/
and then:
PlaceSearchRequestParams.Builder builder = new PlaceSearchRequestParams.Builder();
builder.setSearchText("Cafe");
builder.setDistance(1000); // 1,000 meter maximum distance.
builder.setLimit(10);
builder.addField(PlaceFields.ID);
GraphRequest request = PlaceManager.newPlaceSearchRequestForLocation(builder.build());
request.setCallback(new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
// Handle the response. The returned ID in JSON is the placeId.
}
request.executeAsync();
If I understand your question correctly you can use fql:
https://api.facebook.com/method/fql.query?query=QUERY
where query should be something like this:
select page_id from place where name = ;
Here is a page for your refrence:
http://developers.facebook.com/docs/reference/fql/place/