http://www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/
결론은
https://graph.facebook.com/me/likes/PAGE_ID
&access_token=ACCESS_TOKEN
이런식으로 호출하고
데이터 없으면
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
try
{
$likes
=
->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;
}
Javascript
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!'
);
}
});
Using the REST API pages.isFan method
PHP$isFan
=
->api(
array
(
"method"
=>
"pages.isFan"
,
"page_id"
=>
$page_id
,
"uid"
=>
$user_id
));
if
(
$isFan
=== TRUE)
echo
"I'm a fan!"
;
Javascript
FB.api({ method: 'pages.isFan', page_id: '184484190795', uid: 'user_id' }, function(resp) { if (resp == true) { Log.info('user_id likes the Application.'); } else if(resp.error_code) { Log.error(resp.error_msg); } else { Log.error("user_id doesn't like the Application."); }});
Using the FQL page_fan table
PHP
$result
=
->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!"
;
JavascriptFB.api({
method:
'fql.query'
,
query:
'SELECT uid FROM page_fan WHERE uid=user_id AND page_id=page_id'
},
function
(resp) {
if
(resp.length) {
alert(
'A fan!'
)
}
else
{
alert(
'Not a fan!'
);
}
}
);
많기도 하다.필살기$signed_request = $facebook->getSignedRequest(); $like =$signed_request['page']['liked'];이게 젤 편하다 리턴값은 boolean
'programming > facebook' 카테고리의 다른 글
페이지에 페이지탭 추가 (0) | 2012.07.06 |
---|---|
offline_access 사용 불가 유효기간 연장법 (4) | 2012.04.24 |
페이지탭 설정 (0) | 2012.04.18 |
pageid 가져오기 (0) | 2012.04.17 |
페이스북 앱등록 참고하자 (0) | 2012.04.06 |