在GRAPH API中检查页面的用户粉丝的方法是什么?

发布于 2024-10-17 03:43:41 字数 165 浏览 3 评论 0原文

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

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罪歌 2024-10-24 03:43:41

更新2:
要检查当前用户是否是登陆您的选项卡时 Facebook 页面的粉丝,请检查此 答案


更新:
您可以使用 likes 连接来检查用户是否是某个页面的粉丝:

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 进行检查的方式:

<?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的类似脚本:

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:

$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 表,您需要:

  • 任何有效的 access_token(如果是公开的)(Facebook 上的任何人都可以看到)。
  • user_likes 权限(如果查询当前用户)。
  • friends_likes 权限(如果查询用户的好友)。

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.
不回头走下去 2024-10-24 03:43:41

这是另一种方法,它依赖于 Facebook 发送到的signed_request POST 变量每个选项卡应用程序页面(如果您打开了“OAuth 2.0 for Canvas”高级选项。

这样做的好处是您不需要发送另一个 fql.query。

Here's another approach that relies on the signed_request POST variable that Facebook sends to every tab app page (if you have the "OAuth 2.0 for Canvas" advanced option turned on.

The nice thing about this is you don't need to send another fql.query.

活雷疯 2024-10-24 03:43:41

或者,如果您想要显示一些内容(如果他们是粉丝或制作了一些动态内容),您可以使用 fbml。

例子:

<fb:fbml version="1.1">
    <fb:visible-to-connection>This part is visible for fans only!
        <fb:else>This part is visible for non-fans</fb:else>
    </fb:visible-to-connection>
</fb:fbml>

Or you can use fbml if you whant for example show some content if they are fan or made some dinamic stuff.

example:

<fb:fbml version="1.1">
    <fb:visible-to-connection>This part is visible for fans only!
        <fb:else>This part is visible for non-fans</fb:else>
    </fb:visible-to-connection>
</fb:fbml>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文