Stream FQL shows blank messages (which are my posts on other's walls) - but only with 1 App - facebook

I've been struggling with this one for a few days.
I use a query like this to get my posts on my wall:
select post_id, viewer_id, app_id, source_id, updated_time, created_time, filter_key, attribution, actor_id, target_id, message, attachment, permalink from stream where source_id = 100003203496908 and updated_time >'1362480430'
This is behaving differently, depending on the App ID. The apps appear to have identical settings, and the users appear to have identical permissions.
With the App that is working properly, it returns only my posts on my wall.
With the app that is not working properly, it returns my posts on my wall. But it also returns some rows that have empty message and permalink, like this:
(
[post_id] => 100003203496908_367088630074584
[viewer_id] => 100003203496908
[app_id] =>
[source_id] => 100003203496908
[updated_time] => 1362487503
[created_time] => 1362487503
[filter_key] =>
[attribution] =>
[actor_id] => 100003203496908
[target_id] =>
[message] =>
[attachment] => Array
(
[description] =>
)
[permalink] =>
)
From some testing, I've been able to determine that these are posts I have made on others' walls. Which I don't think should be returned here. The Post_id also looks to be bogus.
Any ideas? Where should I look? Anything with App settings or permissions that would cause something like this in one app but not another?

Related

Facebook API: publish_stream permission works only once

I am working on one application based on Web to post on the wall, comment, like and delete post through the API of Facebook. I ask for these permissions in the register step:
***'scope' => 'publish_actions,read_stream,publish_stream'***
and after registration I can do everything: Post on the wall, comment a post, like and delete. But once I logout from my application and then log in again, take the proper token from my database and try to do the same things, I find that I can post on the wall and delete post but when I try to like or comment I found this error:
*Fatal error: Uncaught OAuthException: (#200) Requires publish_stream permission or Requires extended permission:
publish_actions thrown in...*.
But in fact when I asked about the permission of the user to facebook I have this answer:
*Array ( [data] => Array ( [0] => Array ( [installed] => 1 [read_stream] => 1 [status_update] => 1 [photo_upload] => 1 [video_upload] => 1 [create_note] => 1 [share_item] => 1 [publish_stream] => 1 [publish_actions] => 1 ) ) )*
What I am doing wrong? Thanks!
When the user logs into facebook again, you should refresh their token in your database and use the updated version with any API calls you make.

Accessing data using facebook graph API in fb_graph [rails]

I encounter something annoying while playing around with the facebook graph API. I'm using fb_graph which is a ruby wrapper for the facebook sdk. I'm not sure if this issue I encounter is a limitation of the facebook sdk or I should contact the owner of fb_graph.
So, using fb_graph, this is how I would connect to a user:
jane = FbGraph::User.fetch('janeid', :access_token => "janeaccesstoken")
jane.friends will list all of jane's friends. However, if I try to get jane's friends birthday or email, it returns nil. In other words,
jane.friends[0].birthday => nil
But, I can access friends[0] birthday this way:
bill = FbGraph::User.fetch(jane.friends[0].id, :access_token => "janeaccesstoken")
In other words, if I wanted a list of all jane's friends' birthdates, I cannot do this:
#jane.friends.each do |friend|
puts friend.birthday
end
instead, it will have to be something like this
#jane.friends.each do |friend|
friendname = FbGraph::User.fetch(friend.id, :access_token => "janeaccesstoken")
puts friendname.birthday
end
I guess it's not too bad but it does make me wonder why this is the case, because actually only some info is nil. Name, for example, is not.
#jane.friends.each do |friend|
puts friend.name # => works!
end
The answer is here:
https://github.com/nov/fb_graph/issues/237.

Why does Facebook Credits callback payments_get_items occasionally not pass user ID?

Our facebook canvas app is having this problem where now, several times a day, the credits callback is passing a signed_request with the following contents:
Array
(
[algorithm] => HMAC-SHA256
[credits] => Array
(
[order_id] => 9005967273834
[order_info] => "item104"
)
[issued_at] => 1319329443
[user] => Array
(
[country] => do
[locale] => es_LA
[age] => Array
(
[min] => 0
[max] => 12
)
)
)
Notice anything missing? That's right! No user_id, buyer, or receiver is given!
We can't tell facebook what the price or description of an item is without knowing who is receiving the item.
This seems like a bad bug! This problem started happening on Oct 11, 2011
This is definitely an intermittent bug, so the only work-around is to pass the user ID from your own code into the order_info field of the item. Then use that instead of the credits receiver if the user information is missing.
I don't like that I have to do this, but it seems necessary.
I noticed this as well on my app and from what I can see the missing user IDs happen when Facebook indicates an age bracket of min 0 and max 12 years for the user. I assume that this might be the result of under 13 year olds being prevented from making purchases with Facebook credits.
Which makes me wonder what they are doing on Facebook to start with...

Facebook GetMutualFriends Method failing for no clear reason

I've an application that runs on a webpage, it has a list of facebook id's and run through them checking if the logged user has any mutual friends with the id's on the list; for making this verificaton I'm using the Rest API with the friends.getMutualFriends metond, I'm using this method becasue in this way I can get the mutual friends without having both users authenticated, I just need the authentication for the origin userid, in the case of FQL or using the Graph API both users should be connected so that I can get the mutual friends, this is why the getMutualFriends method is so useful in this case. The problem that I'm having is that when I try to pull the mutual friends for a user that has a lot of friends then I get this error
"error_code": 18,
"error_msg": "This API call could not be completed due to resource limits",
if I try to do that with a user that has less frineds the in will work, I know that saying less or a lot is novet very accurate , so , lets take a look at this example, if I try to execute this call with a user that has 300 friends the call will work, but if I try to do that exact same thing with a user that has 700 friends it'll return back with the error that I put above, so I thought that it could be the amount of calls per second so I limited that but it did not worked, I tried resetting the app keys, I've tried with several differente users, I've tried to do it with a new application, and even if I just try make one call to compare 2 users it'll fail if the user has a large amout of friends, the code that I'm using for this is
function getMutualFriends($facebook, $uid1, $uid2)
{
try
{
$param = array(
'method' => 'friends.getMutualFriends',
'source_uid' => $uid1,
'target_uid' => $uid2,
'callback'=> ''
);
$mutualFriends = $facebook->api($param);
return $mutualFriends;
}
catch(Exception $o)
{
return serialize($o);
}
return null;
}
function getMutualFriendInfo($facebook, $uid1, $uid2)
{
$mutualfriends=getMutualFriends($facebook, $uid1, $uid2);
if (is_array($mutualfriends))//!=''))
{
$friend_uids = implode(",",$mutualfriends);
try
{
$param = array(
'method' => 'users.getInfo',
'uids' => $friend_uids,
'fields' => 'name,pic_square,pic_big',
'callback' => ''
);
$friend_info = $facebook->api($param);
return $friend_info;
}
catch (Exception $o)
{
return serialize($o);
}
}
return serialize($mutualfriends);
}
So my questions are, is there anything that I'm doing wrong on this cade so that it fails? Is there any othere way to do this besides the friends.GetMutualFriends method? I've already tried with this SELECT uid1 FROM friend WHERE uid2=[targetID] AND uid1 IN (SELECT uid2 FROM friend WHERE uid1=[sourceID]) but it did not worked. Is there any specific origin on this error?
I'm very confused because it works for some users and it doesn't for others, I've searched if there's any api limit but I've not found anything on that, there are no errors on the API dashboard, this code seemed to work before, and if I execute the call on the test console on facebook I'll get the same error,
Thanks for are your help, any idea will be appreciated.
There's a bug reported in facebook.
http://bugs.developers.facebook.net/show_bug.cgi?id=15644
firstly you should migrate from old rest api to new graph api.... because facebook will obsolete the old rest api soon.
secondly try this query
SELECT uid1 FROM friend WHERE uid2='your user id'
I hope that it will work

Facebook Graph API - get a photos album ID

I'm writing an application that uploads a photo to facebook. I'm not supplying an album ID so an album is created on behalf of my app.
My question is: how do I get the album ID the photo was uploaded to?
When I GET the the photo information the album isn't present in the JSON which was my hope.
Jimmy Sawczuk's answer is close, but doesn't work because FQL Photo table columns aid and pid are Rest/FQL API ids, not Graph API ids.
Fortunately the object_id and album_object_id columns in this table are indexable (contrary to the documentation) so this should give you both Rest/FQL & Graph ids for the album:
select aid, album_object_id from photo where object_id = ${GRAPH_PHOTO_ID}
In general object_id fields in Rest/FQL API responses are Graph API id (except for photo notifications, where it's the Rest/FQL id).
Re HonkyHonk's answer: not all photo link urls have a set parameter; in this case I think you can find the Rest/FQL API photo id from its other parameters, and then use Rest/FQL API to get the album id:
For users with 32-bit user-ids: calculate (id << 32) | pid
eg for http://www.facebook.com/photo.php?pid=7518353&id=549683637 this gives 2360873244068853905
Otherwise concatenate id, _ and pid
eg for http://www.facebook.com/photo.php?pid=155052&id=100002937903251 this gives 100002937903251_155052
It would help a lot if Facebook could document something about the two types of ids. Also the Graph API Photo schema should include the album's Graph API id.
This is the easy way to get it :
This issue has been bugging me for a while as well, but I think I have cracked the nut.
The album ID is hidden in the link value, so if you have a photo-post object from the Graph API, you can retrieve the Album ID like this:
NSString *link = [item valueForKey:#"link"];
NSString *album_id = nil;
NSRange fRange = [link rangeOfString:#"set=a."];
if(fRange.location != NSNotFound) {
NSInteger firstPos = fRange.location + 6;
NSInteger endPos = [link rangeOfString:#"." options:NSLiteralSearch range:NSMakeRange(firstPos, 25)].location;
album_id = [[link substringWithRange:NSMakeRange(firstPos, endPos - firstPos)] copy];
}
It could probably all be stripped down to one line of code, but I think this is more readable.
For getting the album information use:
[facebook requestWithGraphPath:album_id andDelegate:delegate];
For getting all the photos in an album use:
[facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/photos", album_id] andDelegate:delegate];
Hope this can help someone.
If I'm understanding you correctly, you have the photo ID but need the album ID. You could try using the photo FQL table with the following query:
SELECT aid, pid FROM photo WHERE pid = '<your photo id>'
Long, clunky, but theoretically valid way:
http://graph.facebook.com/userid/albumswill get you a list of all the albums the user lets you see, then you can search the album objects (api here) for created_times that match the time you created the album, which you can store when you create the album.
This is almost certainly a horrible way to do it, but it should work.
Richard Barnett's solution works well for me, I use this as an FQL query through the Graph API to get a JSON response like I would for any other Graph API query:
https://graph.facebook.com/fql?q=select+album_object_id+FROM+photo+WHERE+object_id='[PHOTOID]'
This returns:
{
"data": [
{
"album_object_id": "10150531092908837"
}
]
}
Then you can access the album ID using:
<?php
$strPhotoAlbumID = $objFacebookAPI->data[0]->album_object_id;
?>
This is the cleanest solution i've found as Facebook constantly change the format of their photo and album URLs so parsing these with RegEx wont work as a long term fix.
I ended up just using the legacy REST api since the album ID is passed with the link to the image in the server response. I then used a regex to pull the id out.
Not the best solution and I wouldn't recommend it but I feel its better than adding another several server requests to the code.
function get_album_id_by_album_name($album_name){//return array of data
$fql = 'SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name="'.$album_name.'"';
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $this->facebook->api($param);
return $fqlResult;
}
String albumID = "https://www.facebook.com/photo.php?fbid=192570127478130&set=a.135556629846147.24342.100001754323389&type=1";
albumID = albumID.split("&set=a.")[1];
albumID = albumID.split("\\.")[0];
System.out.println(albumID);