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

What#39;s method for checking user fan of a page in GRAPH API?(在 GRAPH API 中检查页面的用户粉丝的方法是什么?)
本文介绍了在 GRAPH API 中检查页面的用户粉丝的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)