問題描述
在圖形 api 中,Pages.isFan 方法不起作用,怎么辦圖 api 中查看頁面用戶粉絲的方法?
In graph api, Pages.isFan method not working, what's method for checking user fan of a page in graph api?
謝謝.
推薦答案
更新 2:
要檢查當前用戶是否是登陸您的選項卡時 Facebook 頁面的粉絲,請檢查此 回答.
更新:
您可以使用 likes
連接來檢查用戶是否是某個頁面的粉絲:
UPDATE:
You can use the likes
connection to check if a user is a fan of a page:
https://graph.facebook.com/me/likes/PAGE_ID
&access_token=ACCESS_TOKEN
這將返回一個空數據數組:
This would return either an empty data array:
Array
(
[data] => Array
(
)
)
或者如果粉絲:
Array
(
[data] => Array
(
[0] => Array
(
[name] => Real Madrid C.F.
[category] => Professional sports team
[id] => 19034719952
[created_time] => 2011-05-03T20:53:26+0000
)
)
)
這就是我們使用 PHP-SDK 進行檢查的方式:
So this is how we check using the PHP-SDK:
<?php
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
try {
$likes = $facebook->api("/me/likes/PAGE_ID");
if( !empty($likes['data']) )
echo "I like!";
else
echo "not a fan!";
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_likes'
));
}
// rest of code here
?>
使用JS-SDK的類似腳本:
Similar script usingJS-SDK:
FB.api('/me/likes/PAGE_ID',function(response) {
if( response.data ) {
if( !isEmpty(response.data) )
alert('You are a fan!');
else
alert('Not a fan!');
} else {
alert('ERROR!');
}
});
// function to check for an empty object
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}
代碼取自我的 教程.
雖然 pages.isFan
仍在為我工作,但您可以使用 FQL page_fan
帶有新 PHP-SDK 的表:
While pages.isFan
is still working for me, you can use the FQL page_fan
table with the new PHP-SDK:
$result = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid FROM page_fan WHERE uid=$user_id AND page_id=$page_id"
));
if(!empty($result)) // array is not empty, so the user is a fan!
echo "$user_id is a fan!";
來自文檔:
要閱讀您需要的 page_fan 表:
To read the page_fan table you need:
- 任何有效的
access_token
,如果它是公開的(Facebook 上的任何人都可以看到). user_likes
權限(如果查詢當前用戶).friends_likes
權限(如果查詢用戶的好友).
- any valid
access_token
if it is public (visible to anyone on Facebook). user_likes
permissions if querying the current user.friends_likes
permissions if querying a user's friend.
這篇關于在 GRAPH API 中檢查頁面的用戶粉絲的方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!