问题描述
我想我会疯了我不能得到它的工作。我只想检查一个用户是否喜欢我的页面与javascript在一个
iFrame
应用程序。 FB.api({
method:pages.isFan,
page_id:my_page_id,
},function(response){
console.log(response);
if(response){
alert('你喜欢');
} else {
alert('你不喜欢(');
}
}
);
返回:False
但是我是我的页面的粉丝,所以不应该返回true!!
我的头发脱了这个,你的代码只有在用户授予了不太理想的扩展许可的情况下才有效。
地狱,如果您打开Canvas高级选项的 OAuth 2.0
,Facebook将发送一个 $ _ REQUEST ['signed_request']
以及您的标签应用程序中请求的每个页面。如果您解析了signed_request,您可以获取有关用户的一些信息,包括是否喜欢该页面。
函数parsePageSignedRequest (){
if(isset($ _ REQUEST ['signed_request'])){
$ encoded_sig = null;
$ payload = null;
list($ encoded_sig,$ payload)= explode('。',$ _REQUEST ['signed_request'],2);
$ sig = base64_decode(strtr($ encoded_sig,'-_','+ /'));
$ data = json_decode(base64_decode(strtr($ payload,'-_','+ /'),true));
返回$数据;
}
返回false;
}
if($ signed_request = parsePageSignedRequest()){
if($ signed_request-> page->喜欢){
echo该内容仅供粉丝使用! ;
} else {
echo请点击Like按钮查看此标签!;
}
}
I think I'm going crazy. I can't get it to work.
I simply want to check if a user has liked my page with javascript in an iFrame
app.
FB.api({
method: "pages.isFan",
page_id: my_page_id,
}, function(response) {
console.log(response);
if(response){
alert('You Likey');
} else {
alert('You not Likey :(');
}
}
);
This returns: False
But I'm a fan of my page so shouldn't it return true?!
I tore my hair out over this one too. Your code only works if the user has granted an extended permission for that which is not ideal.
In a nutshell, if you turn on the OAuth 2.0
for Canvas advanced option, Facebook will send a $_REQUEST['signed_request']
along with every page requested within your tab app. If you parse that signed_request you can get some info about the user including if they've liked the page or not.
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on the Like button to view this tab!";
}
}
这篇关于如何检查用户是否喜欢我的Facebook页面或使用Facebook的API的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!