dsoihsnz85757 2011-01-06 12:40
浏览 43
已采纳

如何使用facebook api获取好友列表中的位置和电子邮件

Please see this below PHP code:

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

$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxx',
  'cookie' => true, // enable optional cookie support
));

try {
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
  error_log($e);
}

if ($facebook->getSession()) {     
    $friendsLists = $facebook->api('/me/friends?fields=id,name,picture,locale,email');
    $session = $facebook->getSession();

$query = "SELECT uid, name,locale,email,hometown_location FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

$params = array(  

    'access_token' => $session['access_token'], 
    'secret' => $session['secret'],
    'sig' => $session['sig'],
    'query' =>$query  

  ); 



  $url = "https://api.facebook.com/method/fql.query?" . http_build_query($params);  
  $data = simplexml_load_file($url);  

//echo $me;

pr($data);
pr($friendsLists);

  echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a>';
} else {
  echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
}

function pr($atr){
    echo "<pre>";
    print_r($atr);
    echo "</pre>";
}
?>

I am getting out put as below:

[user] => Array
(
    [0] => SimpleXMLElement Object
        (
            [uid] => xxxxxxxxxxxxx
            [name] => Deepak Rathi
            [locale] => en_US
            [email] => SimpleXMLElement Object
                (
                )

            [hometown_location] => SimpleXMLElement Object
                (
                )

        )

    [1] => SimpleXMLElement Object
        (
            [uid] => xxxxxxxxxxxx
            [name] => Aakriti Rovin Ranu
            [locale] => en_GB
            [email] => SimpleXMLElement Object
                (
                )

            [hometown_location] => SimpleXMLElement Object
                (
                )

        )
)

My problem is that 'email' and 'hometown_locations' is empty here.I need both information in friendlist.What need to do there ..?Please give any support.

Regards Deepak

  • 写回答

1条回答 默认 最新

  • dongshan2004 2011-01-06 13:15
    关注

    Data returned by Facebook is json encoded, not XML so I suggest you adjust your code.

    About your question - those fields are not empty, they are SimpleXMLElement Objects. Read this http://php.net/manual/en/class.simplexmlelement.php to get to know what to do next.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集