Get user ID of someone that has liked my page
I would like to capture the user id of a person that has liked my application. On the page_fan fql page it says, "Query this table to return information about the fan of a Facebook Page. You can query this table without an auth_token or a session key."
I am using the following code:
$data = $facebook->api( array( 'method' => 'fql.query', 'query' =>
'SELECT uid FROM page_fan WHERE page_id="page_id" and uid="'.$me['id'].'"' ) );
print_r($data);
//if the user is fan, uid will be returned, otherwise, an empty array.
I only get a null array. I don开发者_Go百科't want to ask for extended permissions.
There is no way to get a list of Page fans using the API. You can only go in the other direction -- ask a single user for permissions (user_likes) and then find out what pages he likes. However, you can use Page Tabs to detect when a user that hits your app likes the Page that it's on. You don't even need permissions for this. That is the closest you're going to be able to get.
Details on how to detect whether the viewing user is a fan can be found in the signed_request parameter documentation.
remove the "uid="'.$me['id'].'"
part so you would get all the fans - you might be logged in as the page, and a page can not like itself.. but thats just an option.
Alternatively you can use the graph api to get the members of a page (ie, who liked it):
https://graph.facebook.com/[PAGEID]/members?limit=500&access_token=[oauthtoken]
[oauthtoken] = any token - you dont have to ask for extended permissions.
精彩评论