我如何列出我的粉丝名称和ID?

时间:2012-03-18 05:10:57

标签: php facebook-fql

我是FQL新用户!我有粉丝页面,我是管理员。现在,我想使用FQL列出我的粉丝的名字和粉丝的ID?请帮助我!谢谢!

这是我到目前为止所尝试的 -

<?php 
    require_once('src/facebook.php'); 

    $facebook = new Facebook(
                    array( 'appId' => 'id', 
                           'secret' => 'secret', 
                           'cookie' => true, )); 
    $result = $facebook->api(
                   array( 'method' => 'fql.query', 
                          'query' => 'select uid from page_fan 
                                       where page_id = xxxxxx' )); 
    $fb_fans = $result[0]['uid']; 
?> 
<?php 
    echo $fb_fans; 
?> 

并显示以下错误 -

  

致命错误:未捕获异常:190:无效的OAuth访问令牌签名。投入

     第1106行的

C:\ AppServ \ www \ src \ base_facebook.php

现在它的工作地点为:

<?php  
require_once('src/facebook.php');  
$facebook = new Facebook(array(  
    'appId'  => 'myid',  
    'secret' => 'secret',  
    'cookie' => true,  
));  
$result = $facebook->api(array(  
    'method' => 'fql.query',  
    'query' => 'select fan_count from page where page_id = xxxx'  
));  
$fb_fans = $result[0]['fan_count'];  
?>  
<?php echo $fb_fans; ?>  

但现在我写了'page_fan中的select uid,其中page_id = xxxx' 这不行!为什么? 我想来自page_fan的uid是一种表格式吗?

这是我的完整代码:

<?php 
    require_once('src/facebook.php'); 

    $facebook = new Facebook(
                    array( 'appId' => 'id', 
                           'secret' => 'secret', 
                           'cookie' => true, )); 
    $result = $facebook->api(
                   array( 'method' => 'fql.query', 
                          'query' => 'select uid from page_fan 
                                       where page_id = xxxxxx' )); 
    $fb_fans = $result[0]['uid']; 
?> 
<?php 
    echo $fb_fans; 
?> 

谢谢!

2 个答案:

答案 0 :(得分:2)

您使用的是php sdk吗?

如果是这样,您是否尝试使用图API?

$ret = $facebook->api( array(
                         'method' => 'fql.query',
                         'query' => 'SELECT . . . ',
                     ));

或者你可以玩explorer

编辑:

尝试这样的事情:

// Make sure you have a token to do so beforehand

$fql = $facebook->api( array(
       'method' => 'fql.query',
       'query' => 'SELECT uid2 FROM friends WHERE uid1=me()',
));

var_dump(json_decode($fql, true)); // test the responce

我在代码中看不到任何令牌!

来自fb来源

*将page_id = XXX更改为您的网页ID *

$app_id = 'YOUR_APP_ID';
  $app_secret = 'YOUR_APP_SECRET';
  $my_url = 'POST_AUTH_URL';

  $code = $_REQUEST["code"];

 //auth user
 if(empty($code)) {
    $dialog_url = 'https://www.facebook.com/dialog/oauth?client_id=' 
    . $app_id . '&redirect_uri=' . urlencode($my_url) ;
    echo("<script>top.location.href='" . $dialog_url . "'</script>");
  }

  //get user access_token
  $token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
    . $app_id . '&redirect_uri=' . urlencode($my_url) 
    . '&client_secret=' . $app_secret 
    . '&code=' . $code;
  $access_token = file_get_contents($token_url);

  // Run fql query
  $fql_query_url = 'https://graph.facebook.com/'
    . '/fql?q=SELECT+uid+FROM+page_fan+WHERE+page_id=XXXX'
    . '&' . $access_token;
  $fql_query_result = file_get_contents($fql_query_url);
  $fql_query_obj = json_decode($fql_query_result, true);

  //display results of fql query
  echo '<pre>';
  print_r("query results:");
  print_r($fql_query_obj);
  echo '</pre>';

答案 1 :(得分:1)

在此页面中,您可以获得粉丝的ids .. facebook manual page_fan table

然后从uids你可以通过以下方式得到名字:

SELECT name FROM user WHERE uid in ()