-1

我正在尝试从 Facebook API 存储家乡和位置,但在从家乡和位置数组中提取数据时遇到问题。(我已经获得了令牌许可)

"hometown": {
    "id": "210336945633449",
    "name": "xxxx, yyyyy"

我正在使用以下代码

function getUserData() {
        $fb_cookie = $this->getCookie();
        if($fb_cookie) {
            $url = 'https://graph.facebook.com/me?access_token='.$this->getAccessToken();
            $data = json_decode($this->getDataFromUrl($url));
            $fb['id'] = $data->id;
            $fb['name'] = $data->name;
            $fb['first_name'] = $data->first_name;
            $fb['last_name'] = $data->last_name;
            $fb['link'] = $data->link;
            $fb['birthday'] = $data->birthday;
            $fb['gender'] = $data->gender;
            $fb['email'] = $data->email;
            $fb['location'] = $data->location; // <-----
$fb['hometown'] = $data->hometown; // <-----
            $fb['timezone'] = $data->timezone;
            $fb['locale'] = $data->locale;
            $fb['updated_time'] = $data->updated_time;
            $fb['picture'] = 'http://graph.facebook.com/'.$data->id.'/picture';


            //tokens
            $fb['token'] = $fb_cookie['access_token'];
            $fb['token_expires'] = $fb_cookie['expires'];
            return $fb;
        }
    }

谁能帮我解决这个问题?

谢谢

4

2 回答 2

0

由于 location 和 hometown 也是你这样使用的对象,因此获取这些值。

$fb['location'] = $data->location->name;
$fb['hometown'] = $data->hometown->name; 
于 2012-09-29T16:46:12.823 回答
0

要获取位置名称,请尝试:

$loc=$data->getLocation();
$loc_name=$loc->getName();

上面的代码适用于 Facebook SDK v4。(此 SDK 需要 PHP 5.4.0 或更高版本)

于 2014-11-19T22:22:38.103 回答