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

如何使用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.

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

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理