检查GRAPH API中页面的用户粉丝的方法是什么? [英] What's method for checking user fan of a page in GRAPH API?

查看:86
本文介绍了检查GRAPH API中页面的用户粉丝的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在图表API中, Pages.isFan 方法不起作用,什么是



谢谢。

解决方案

更新2:

要检查当前用户是否在Facebook页面的粉丝登陆您的标签,请检查此

更新:

您可以使用喜欢连接来检查如果用户是页面的粉丝:

  https://graph.facebook.com/me/likes/PAGE_ID 
& access_token = ACCESS_TOKEN

这将返回一个空数据数组:

  Array 

[data] => Array




或者如果粉丝:

 code> Array 

[data] => Array

[0] => Array

[name] =>皇马CF
[category] ​​=>专业运动队
[id] => 19034719952
[created_time] => 2011-05-03T20:53:26 + 0000





所以这是我们如何检查使用PHP-SDK:

 <?php 
require'../src/facebook.php';

//创建我们的应用程序实例(将其替换为您的appId和密码)。
$ 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我喜欢!
else
回声不是风扇!;
} catch(FacebookApiException $ e){
error_log($ e);
$ user = null;
}
}

if($ user){
$ logoutUrl = $ facebook-> getLogoutUrl();
} else {
$ loginUrl = $ facebook-> getLoginUrl(array(
'scope'=>'user_likes'
));
}

//其余代码
?>

使用JS-SDK的相似脚本:

  FB.api('/ me / likes / PAGE_ID',function(response){
if(response.data){
if(!isEmpty(response.data )
alert('你是粉丝!');
else
alert('不是风扇!');
} else {
alert(' ERROR!');
}
});

//检查空对象的函数
函数isEmpty(obj){
for(var prop in obj){
if(obj.hasOwnProperty(prop ))
return false;
}

返回true;
}

从我的教程






虽然 pages.isFan 仍然适用于我,您可以使用FQL page_fan 表与新的PHP-SDK:

  $ result = $ facebook-> api(array(
method=>fql.query,
query=>SELECT uid FROM page_fan WHERE uid = $ user_id AND page_id = $ page_id
));
如果(!empty($ result))//数组不为空,那么用户就是粉丝!
echo$ user_id是一个粉丝!;

从文档中:


要阅读您需要的page_fan表:




  • 任何有效的 access_token 如果是公开的(Facebook上的任何人都可以看到)。

  • user_likes 查询当前用户的权限。 b $ b
  • friends_likes 查询用户的朋友时的权限。



In graph api, Pages.isFan method not working, what's method for checking user fan of a page in graph api?

Thanks.

解决方案

UPDATE 2:
To check if the current user is a fan of the Facebook page on landing at your tab check this answer.


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
        (
        )

)

Or if fan:

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => Real Madrid C.F.
                    [category] => Professional sports team
                    [id] => 19034719952
                    [created_time] => 2011-05-03T20:53:26+0000
                )

        )

)

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
?>

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;
}

Code taken from my tutorial.


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!";

From the documentation:

To read the page_fan table you need:

  • 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中页面的用户粉丝的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆