I am attempting to access a user's friends work and education history using the Graph API. I have included both permissions in the auth dialogue. I have tried accessing them using FQL but have had no luck.
try{
$fql = "select friends_education_history from permissions where uid=" . $user;
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
}
I'd prefer to access the info without using FQL but at this point, I need to figure out ANY way. Is there a way to do something like this:
if($user_id) {
try {
$friends = $facebook->api("/me/friends");
}
catch(Exception $o){
d($o);
}
}
?>
And then call the respective variables?
Your FQL query would look something like this:
SELECT education,work from user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Above query will fetch all education and work objects from friends of the logged in user.
SELECT education,work from user WHERE uid = <YOUR FRIENDS USER ID>
Above query will get education and work for just the one user id you provide
Hope this helps!
The User graph api object has fields education and work.
Permissions user_education_history & friends_education_history are required for the first, user_work_history & friends_work_history for the second.
These fields are optional & a user can restrict their visibility via her profile page, so even having granted the permissions the api may return nothing.
Use the Graph api explorer to have a play.
Related
I have built an app using the PHP Facebook SDK. It allows users to authenticate my app with facebook OAth so that they can update their status' via my App. This works great, however a lot of my users have business pages and they want to update the status on their business page not their main personal feed. How is this possible? Below is what I have so far.
if ($status != ''){
try {
$parameters = array(
'message' => "$status"/*,
'picture' => $_POST['picture'],
'link' => $_POST['link'],
'name' => $_POST['name'],
'caption' => $_POST['caption'],
'description' => $_POST['description']*/
);
//add the access token to it
$parameters['access_token'] = $access_token;
//build and call our Graph API request
$newpost = $facebook->api(
'/me/feed',
'POST',
$parameters
);
$success['status'] = "$xml->status";
$xml2 = new XMLGenerator($success, 'facebook','status');
$returnData = $xml2->output;
$returnData = APIResponse::successResponse('200', "$xml->status");
} catch (Exception $e) {
$returnData = APIResponse::errorResponse('400', 'Facebook Error: '.$e);
}
I assume I would have to change '/me/feed'? but to what? What is they have multiple pages how would my app know which page to post to?
Any help with this would be much appreciated.
You can substitute me with the PAGE_ID to post to a page e.g., /013857894/feed. Make sure that you have completed the OAuth process with the manage_pages and publish_stream permissions. You can learn more at the link below:
https://developers.facebook.com/docs/reference/api/page/#statuses
If the user has multiple Pages then you will first need to give them some way of selecting which page they want to post to. You can find out which Facebook Pages a given user is the administrator of by calling /me/accounts for that user. You can find out more about this approach in the Connections section of this page:
https://developers.facebook.com/docs/reference/api/user/
I'm trying to get a list of friends and with the following information {email, birthday, relationship status}
Right now I can only get the name and id with this snippet
FB.api('/me/friends', function(response) {
...
});
Is there any way to get that information or is just limited to name and id?
Or, using the current APIs
$facebook->api('me/friends?fields=name,birthday,relationship_status')
This will work with any field of the User object you can retrieve
It's not possible to retrieve friends' email addresses at all, and other fields may require your user to grant you a specific Permission first, but the basic format of the API call is the same.
The example above needs friends_birthday and friends_relationship_status permissions
$friendsIds = array(1,2,3);
$requestInfo = array(
'method' => 'users_getInfo',
'friends' => $friendsIds,
'user_info' => array('last_name', 'first_name', 'uid', 'birthday')
)
$userDetails = $facebook->api->($requestInfo);
print_r($userDetails);
in js checkout
how to use facebook API getting friend's list in javascript
I'm trying to retrieve users events using the facebook php sdk, but i'm stuck, the api return an empty array
$user = $me['id'];
$fql = "SELECT eid, name, start_time, end_time
FROM event
WHERE eid IN (SELECT eid
FROM event_member
WHERE uid = 1552544515)
ORDER BY start_time LIMIT 5";
$params = array(
'method' => 'fql.query',
'query' => $fql,
);
try {
$result = $facebook->api($params);
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
thanks in advance.
If this is returning nothing, the most likely reason is that your user hasn't granted the user_events Permission during the Authentication flow.
Looking at your comments above, you may have added user_events to the permissions granted when a user goes through the Authenticated Referrals flow or via App Center, but regular users accessing the app directly need to go through one of the authentication flows from the document above, you're probably not doing this
I see that I can access a friend's groups via the Graph API:
https://graph.facebook.com/11111111/groups
... but how do I access it via FQL? (I am searching the documentation extensively before asking these questions, sorry if I'm asking an obvious one).
if you want to get the groups of user with the id 1111111
you can write this query:
select gid, name from group
where gid in (select gid from group_member where uid = 1111111)
don't forget you need to have the friends_groups permission in order to get this data
the documentation for those tables can be found here:
http://developers.facebook.com/docs/reference/fql/group_member/
http://developers.facebook.com/docs/reference/fql/group/
Yeah. I tried it did not work with FQL . But you can use the following code to get it via graph api
function get_groups($facebook)
{
require_once 'config.php';
global $facebook;
$groups = $facebook->api('/me/groups');
var_dump($groups);
return $groups;
}
The config file has the following :
<?php
require_once("facebook.php");
$app_id = "";//put the app id
$app_secret = "";//put app secret code inside " "
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
if(is_null($facebook->getUser()))
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");//include the permission you want here
exit;
}
?>
Hey all,
I've made a facebook application for a contest, which allows users to upload their photo. Once uploaded, the photo gets posted to a dedicated album on their profile. Once the photo is there, the users should collect as many likes as possible.
Currently i have tried both the Facebook Graph API and Facebook FQL to retrieve the amount of likes, but the retrieved likes don't always match the likes on a users profile.
Some users claim to have more then 200 likes, yet the API only returned a maximum of 101 likes so far.
All users are requested to grant the application the following permissions:
user_hometown, publish_stream, read_stream, user_photos and offline_access
Using Facebook PHP SDK 3.0.1 I tried this FQL query to collect the amount of likes of a photo:
# fql query
$fql = "SELECT object_id FROM like WHERE object_id=" . $photo_id;
# api request
$request = array(
'method' => 'fql.query', 'query' => $fql
);
# run batch request
$likes = $this->facebook->api($request);
# return like count
return count($likes);
I also tried the following Graph API request (Also with Facebook PHP SDK 3.0.1) to collect the amount of likes of a photo:
$likes = $this->facebook->api($photo_id.'/likes');
return count($likes['data']);
Strangely, neither seem to return correct results. I can understand if the API is slightly inaccurate, but according to the API some pictures recieved 100 likes this morning and then 0 likes a few hours later.
Does anyone have any ideas what i might be doing wrong? Do the photo's and their albums need to be public? Do the people who liked the photo need to have a public profile in order to show up in the API? Do i need to request additional permissions?
Any help or suggestions will be greatly appreciated!
Just had the same problem here. The likes seems to be paginated by hundreds by default. Override this setting by using the "LIMIT" query option.
Does anyone have any ideas what i might be doing wrong?
yes, I believe that it is against Facebook policy to use their likes plugin for a contest. See: https://www.facebook.com/promotions_guidelines.php
# fql query
$fql = "SELECT like_info FROM photo WHERE object_id=" . $photo_id;
# api request
$request = array(
'method' => 'fql.query', 'query' => $fql
);
# run batch request
$likeInfo = $facebook->api(array(
'method' => 'fql.query', 'query' => $fql
));
var_dump($likeInfo);die;
=> get like info of photo