Facebook Graph API me / accounts返回空的Json数据数组

时间:2012-01-03 01:44:38

标签: facebook-graph-api

我为https://graph.facebook.com/me/accounts?access_token=XXXXXXXXX获取以下空数据数组:

第1步: - 使用Oauth URL获取代码

步骤2: - 使用Oauth访问令牌URL中的上述CODE获取访问令牌

提前致谢。

2 个答案:

答案 0 :(得分:1)

access_token有哪些权限? (见https://developers.facebook.com/tools/debug)您可能没有要求正确的。

答案 1 :(得分:1)

function get_html($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FAILONERROR, 0);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

function get_json($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FAILONERROR, 0);
    $data = curl_exec($ch);
    curl_close($ch);

    return json_decode($data);
}

if ($_GET['type'] == "page") {

    $pages =
        get_json("https://graph.facebook.com/me/accounts?fields=id,picture,name&access_token=$token")->data;

    foreach ($pages as $page) {
        $page->picture;
        $page->name;
        $page->id;
    }
}