FB/Facebook current logged in user's pages list - facebook

I will give a fan page link to any user in a facebook application, and tell that user to do like that page.
so how can I check that the specified user has clicked on like, I to check this by a script/FBML.
I want a script that returns true/false if I give a parameter of that page.
or I want to get pages list of that user so I can search that I want in that list.
How can I do this or is there any fbml which can extract pages list of current loggedin user.
Looking forward for your kind reply ans sorry for my english.
Thanks in advance...
Regards,
Muhammad Hanif

Well I'm not sure what you are asking, but I'll try my best answering your "questions".
I want a script that returns
true/false if I give a parameter of
that page.
So you already have the user id and the page id, you can check if the user is fan in two ways:
pages.isFan:
$isFan = $facebook->api(array(
"method" => "pages.isFan",
"page_id" => $page_id,
"uid" => $user_id
));
if($isFan === TRUE)
echo "I'm a fan!";
FQL:
$result = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid FROM page_fan WHERE uid=$user_id AND page_id=$page_id"
));
if(count($result))
echo "$user_id is a fan!";
Source: Facebook API: Check If A User Is Fan Of A Facebook Page.
You can also capture when the user "Like"s something, for this check Tracking Facebook “Like” Referrals.

Related

Facebook access token for post message in timeline

I am trying to do something like this. Lets say a user used FB Connect for registration in our site, so I can get the "uid" of facebook and I can store in DB. Now what I want each time that user will visit a store details page or item details page I will post that store/item image with link, photo, description etc to FB timeline.
Something like this:
$post_id = $facebook->api('/me/feed/', 'post', array(
'message' => $products_name, // item name
'link' => 'http://www.blabla.com/item/myshoes', // item url
'picture' => $fb_img_src, // item image
'caption' => $products_name, // item name for caption
'description' => $products_description // item description
));
} catch (FacebookApiException $e) {
$user = null;
}
This process works fine if user logged in to FB by using our FB app. But as I said I want to post if they not even logged in by using their facebook "uid".
Is it possible to authenticate that user depending on facebook "uid"?
Thanks in advance! Any clue/help will be appreciated!
I strongly believe that posting anything to user's Facebook without their's consent or even their action will surely and quickly encourage them to leave your site forever. Do not do this.
Anyway - to answer your question:
Yes, it is possible to get access to user's Facebook and "do stuff", especially when a user is logged in both on Facebook and on your site. You just need to obtain user's access token (read about it in the docs), and make sure the users grants your app all aproppriate permissions. There are also access tokens that can be used offline (user is not even online), but I'm not going to discuss it here.
One way to obtains user's access token is to redirect the user to FB login url providing your APP_ID (as described in FB developers docs). FB will then redirect the user to your Fb-login URL with access code/access token, which enables you to do something like posting to users timeline.
Of course actions that you can take are limited according to permissions said user has granted for your app. And I have to remind you - it's a thin ice you're stepping on.

Posting to my FB page as the page owner/admin, not my profile name/id

I have attempted to find an answer vis-a-vis the FB api, Google and this forum.
What I would like to know is what type of a value do I use for the 'from' field when posting to /PAGE/feed using the FB api.
I began including a 'picture' field and now posts to my page are happening as my fb account and not the page like it normally does.
You must first obtain the page access token before you can post as the page. You're going to need the manage_pages and publish_stream permissions too. To get the page access token, you should run the request using the page administrator's account.
assuming you've done the login and permission (scope) setting correctly, the following code might give you an idea of how this works. assuming $page_id is the variable holding your page's ID number.
<?php
if ($me)
{
$pageAccessToken = $facebook->api('/'.$page_id.'?fields=access_token');
if (isset($pageAccessToken['access_token']))
{
// switch to use page token instead of user token
$facebook->setAccessToken($pageAccessToken['access_token']);
// setup your post
$params = array('message' => "This is a test post",
'picture' => "http://nypsit.edu.sg/images/nypsit.jpg",
'name' => "NYP SIT Homepage",
'link' => "http://www.nyp.edu.sg/sit/school-of-information-technology",
'description' => "Nanyang Polytechnic - School of Information Technology"
);
// post to page timeline
$status = $facebook->api('/'.$page_id.'/feed', 'POST', $params);
// check if post successful
if (isset($status['id']))
{
echo "<h3>Message posted to page timeline!!!</h3>";
}
}
}
?>

How to check if user has liked the facebook application?

Previously, I was checking if user has liked the facebook app or not using the following code:
$fql= "SELECT uid FROM page_fan WHERE page_id = '$appid' and uid='".$me['id']."'";
$param=array(
'method' => 'fql.query',
'query' => $fql,
'access_token' => $access_token
);
$fqlResult1 = $facebook->api($param);
$hasliked = count($fqlResult1);
But now this code doesn't work anymore. Is there any solution to this problem?
Facebook has blocked the feature that we can check whether facebook apps are blocked or not from about 6,8 months.
You could use:
$facebook->api("/$user/likes");
It provides list of likes for the user. If you application is in the list then its liked by the user else not.
Did you mean something like that.
you can check by specifying your page id while giving api call like this
https://graph.facebook.com/me/Likes/" + pageId/appId + "?access_token=" + oAuthToken
if response contains data it means your page/app is liked otherwise not.

Birthday field not returning data

Basically I got 2 question here:
once the user given permission to a facebook application at fbconnect, is it anytime the application can post the fb user's wall?
How about later when they logout from facebook already?
Does application owner still have the permission to like post to their wall? Or need to wait till they login to facebook connect the second time only can re-access the information?
Somehow the birthday field for all my friends are returning as empty.
I am using latest php sdk from github.
$friends = $facebook->api('/me/friends');
$_SESSION['fb_user_friends'] = $friends;
foreach ($friends as $key=>$value)
{
echo '<br>';
foreach ($value as $fkey=>$fvalue)
{
//all the query return values, except birthday and birthday_date field
//birthday and birthday_date field totally don't have any friend's DOB appearing, all empty.
//wonder why
$fql = "SELECT uid, first_name, last_name, name, birthday, birthday_date FROM user WHERE uid=".$fvalue[id];
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$userDetails = $facebook->api($param);
print_r($userDetails);
}
}
EDIT: this is no longer an accurate answer
-It can post on the wall if you asked for that permission.
'req_perms' => 'publish_stream,...
To post on wall of loged out user you need another permission "offline_access". All permissions: http://developers.facebook.com/docs/authentication/permissions
-Birthday. I experienced the same. Birthday sometimes empty because user didn't provided it or set the security high and apps can't ask for it. And you have to ask for 'friends_birthday' permission too at registering to your app.
in 'settings' on your application, go to 'permissions' and enable 'User & Friend Permissions': 'user_birthday', 'friends_birthday'

facebook: how to show content in page only if user likes it

how can i show or display information only if the user is fan or likes my page? there are several pages that do that to catch more fans. thanks!
edit:
like the victorias secret page with this box
http://www.facebook.com/victoriassecret?v=app_117241824971601&ref=ts
My answer applies if you use an iFrame for your tab/canvas. First, you need to ask for permissions (just need basic info from user). Then, make a call to the Javascript API, like so:
FB.api('me/likes', function(response) {
});
This gives a JSON object of everything the user has liked. So, you have to loop through the response and try to find your page. If you are successful in finding it, display the awesome content!
Hope this helps!
Edit: Looking back, my answer was way off. This information is actually contained in the signed_request given by Facebook.
If you mean Facebook Page, use functions from Facebook API: Signed Request
$signed = parse_signed_request($_REQUEST['signed_request'], YOUR_APP_SECRET_KEY);
$signed = Array (
[algorithm] => HMAC-SHA256
[expires] => 13..
[issued_at] => 13..
[oauth_token] => ...
[page] => Array (
[id] => 29...
[liked] => 1
[admin] =>
)
[user] => Array ( [country] => cz [locale] => en_US [age] => Array ( [min] => 21 ) )
[user_id] => ..
)
If current user like your Facebook tab page, you find out from $signed['page']['liked']
If you're using the php sdk, you can use a call to the facebook object api and then determine if they have the like you want them to have.
$path = 'me/likes';
$likes = $facebook->api($path);
More info here
This is a privacy and security setting. Facebook Privacy FAQ
Page Tabs gets Signed Request that contain "liked" field
http://developers.facebook.com/docs/authentication/signed_request/
FQL isFan
http://developers.facebook.com/docs/reference/fql/page_fan/
Old REST API isFan
http://developers.facebook.com/docs/reference/rest/pages.isFan/
Legacy FBML isFan
http://developers.facebook.com/docs/reference/fbml/visible-to-connection/
There doesn't have to be any code involved. Just create a landing page (you could create a jpeg photo and link to the photo) and set that as the default landing page in your page settings. For users who are fans they go directly to the wall posts. All other people (non-fans) go to your specified landing page.
By the way, you realize that people can still access your content by just clicking on one of the tabs, correct? Even the Victoria Secrets example allows you to click on the "wall" tab, for example, and see the content.
A lot of people just like the page because it's the default landing page and they "think" they have to like the page first. It's more social psychology than anything else.
Google for Facewall Script, that should do what you want. But keep in mind to offer an option for users that not have Facebook Account.