How can I check thought the FB Javascript API if the current user is a fan of my app? I need to check this from within the page inserted into the FB's canvas IFRAME, throught the JS SDK...so that I can call a method of a local Flash, and do "something special" for that user.
In PHP, you can achieve this by using their PHP-SDK.
First you're gonna have to query their FQL database. Use the ff query (replace UID with the user's Id and PAGE_ID with your application's Id).
'SELECT uid, page_id FROM page_fan WHERE uid=UID AND page_id=PAGE_ID'
So your code might look like this:
$client = new Facebook(YOUR_PARAMS_HERE);
$result = $client->api(array(
'method' => 'fql.query',
'query' => 'SELECT uid, page_id, type FROM page_fan WHERE uid=1234 AND page_id=4321',
));
This returns an array similar to the ff:
array(
[0] = array(
[uid] = 1234
[page_id] = 4321
[type] = APPLICATION
)
)
FQL page_fan details here.
Related
I'm working on a Facebook app and I need to know if the user likes a specific page or not.
I tried using:
$isFan = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid FROM page_fan WHERE page_id = 'SOMEPAGEID'
AND uid = me()"
));
It returns NULL.
I even tried the javascript SDK:
FB.api('/me/likes/SOMEPAGEID', function(response) {
console.log(response.data);
});
It returns nothing.
I'm asking for the following permissions:
$scope = "email,user_likes";
Am I missing something?
Edit: SELECT * was bad copy-paste... it's SELECT uid
Your permissions look correct but I don't think that FQL queries actually support SELECT *, you have to manually list the fields
So try changing your FQL query to
select page_id from page_fan WHERE uid = me() AND page_id = PAGE_ID
Or it might be you haven't encoded your query properly. This runs for me in the graph explorer https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3Dselect%2Bpage_id%2Bfrom%2Bpage_fan%2BWHERE%2Buid%2B%253D%2Bme%2528%2529
fql?q=select+page_id+from+page_fan+WHERE+uid+%3D+me%28%29
so try using
$isFan = $facebook->api('/fql?q='.urlencode('select page_id from page_fan WHERE uid = me() AND page_id = PAGE_ID'));
$fql = 'SELECT name,aid,photo_count,owner FROM album WHERE owner='.$userId;
$fql = 'SELECT aid,owner,name FROM album WHERE owner IN
(SELECT uid1 FROM friend WHERE uid1 = 100002278102636 LIMIT 1 )';
I am using my codeigniter application to upload photo to an album which will be named current date.Creating album and all other uploads are working fine,but when i tried to select album name from album table using owner field its returning an empty array.But above query works fine with facebook test query widget
https://developers.facebook.com/tools/explorer?fql=SELECT%20aid%2Cowner%2Cname%20FROM%20album%20WHERE%20owner%3D100002278102636
i used API like this
$ret_obj1 = $this->facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
what am i doing wrong...Thanks in advance
My guess is that this is a permission issue. To get these results, you need to be authenticated as a user and have the user_photos and friends_photos permission in your access token. If you don't, the FQL query will return a result and Facebook will filter that result out before it is given to your app, giving an empty data set.
The other possibility is your access token does not belong to user 100002278102636. If that is the case, then the friend subquery will fail.
Also, you should be using album_object_id now instead of aid. It appears that the aid field (and pid) will be removed in November.
Have you tried running your $fql query through urlencode? You'll notice that the one on facebooks graph explorer is encoded but yours is not
$ret_obj1 = $this->facebook->api(array(
'method' => 'fql.query',
'query' => urlencode($fql),
));
As an aside - this query:
$fql = 'SELECT aid,owner,name FROM album WHERE owner IN
(SELECT uid1 FROM friend WHERE uid1 = 100002278102636 LIMIT 1 )';
You are selecting uid1 WHERE uid1 = a known value? Why not just do
$fql = 'SELECT aid,owner,name FROM album WHERE owner = 100002278102636 )';
I have develop Facebook application and added page tab on my page.
I have read Facebook documentation for canvas application development and adding application on page tab.
I want to show different page for people who click on Like button on my page and different page to people who not click on like button.
After reading documentation I found that it is possible using FSQL but I am not getting any result from my sql queries
https://developers.facebook.com/docs/reference/fql/url_like/
https://developers.facebook.com/docs/reference/fql/
require_once 'facebook.php';
// *** Add your Facebook API Key, Secret Key here ***
$appapikey = '*********';
$appsecret = '**********';
$facebook = new Facebook($appapikey, $appsecret);
// $user_id = $facebook->require_login();
//$fql = "select name from user where uid=me()";
//$fql = "SELECT user_id FROM like WHERE object_id='122706168308'";
$fql = "SELECT user_id, object_id, post_id FROM like WHERE user_id=me()";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
echo"hi";
echo"<pre>";
print_r($fqlResult);
echo"</pre>";
Any idea how to make it working?
Thanks.
did you authorized app at first ?
PS: its not FSQL its fql i mean you are not able to use all sql commands in fql
I have create new iframe app on facebook and want to detect whether the user is a fan or not of the current page so I use the $_REQUEST['signed_request'] variable as described here: http://developers.facebook.com/docs/authentication/signed_request/. However $_REQUEST['signed_request'] variable always returns NULL, not what it should actually return. Has anyone ever encountered the same problem? I'm quite familiar with creating apps on facebook but can't figure out what could be the reason of this problem... Any ideas?
Make sure that in your Page tab url you specify the name of the page for example http://yourdomain.com/myapp/index.php instead of just http://yourdomain.com/myapp
The signed request only seems to get posted if you specify the exact page
You can use Facebook Query Language (FQL) to check if the current user is a Fan of your page.
function userIsFan()
{
global $page_id, $facebook, $access_token;
$fql = "SELECT uid from page_fan WHERE uid=me() AND page_id='".$page_id."'";
$param = array('method' => 'fql.query',
'access_token' => $access_token,
'query' => $fql,
'callback' => '');
$response = $facebook->api($param);
if (isset($response[0]))
{
return true;
}
return false;
}
Things to take note of...
me() is a method that automatically gets the user id of the current user.$page_id should be containing your Facebook Page id that you have specified in fbmain.php
Recently I am trying to develop a facebook application that shows the STATUSES of loged in facebook user.
I am succeeded to retrieve information from user table using FQL. But right now I am using this following code to get data from status table.
****BEGIN :: CODE SECTION***********
$sql = "SELECT message,time FROM status WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = ".$myLoginId.")";
$param = array(
// 'method' => 'fql.query',
'method' => 'status.get',
'query' => $sql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
print_r($fqlResult);
***END:: CODE SECTION********
But everytimes it returns Empty Array.
Right Now I am using Library of facebook-php-sdk-v2.1.2-4-g2343fca.tar which I collect from github.com.
can anybody please give me a solution.
Thank in Advance.
You code is working just fine, just a small note, you can use me() to get the current user id:
$fql = "SELECT uid,message,time FROM status WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me())";
$fqlResult = $this->facebook->api(array(
'method' => 'fql.query',
'query' => $fql
));
AND once again, the most important part is acquiring the correct permissions, which are user_status (if you want to get your statuses) AND friends_status (to get your friends' statuses).