将fb访问令牌插入此代码

时间:2015-08-01 06:27:36

标签: php facebook api facebook-graph-api

我有来自谷歌的这个脚本它工作得很好,代码能够从任何页面检索任何Facebook相册 突然它停止了工作 我在谷歌上做了一项研究我发现它需要在代码中实现访问令牌 但我不能单独做任何帮助请 问候

$fb_page_id = "448955931844556";

$json_link = "http://graph.facebook.com/{$fb_page_id}/albums?fields=id,name,description,link,cover_photo,count";
$json = file_get_contents($json_link);

$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

$album_count = count($obj['data']);
for($x=0; $x<$album_count; $x++){

    $id = $obj['data'][$x]['id'];
    $name = $obj['data'][$x]['name'];
    $description = $obj['data'][$x]['description'];
    $link = $obj['data'][$x]['link'];
    $cover_photo = $obj['data'][$x]['cover_photo'];
    $count = $obj['data'][$x]['count'];

    // if you want to exclude an album, just add the name on the if statement
    if(
        $name!="Profile Pictures" &&
        $name!="Cover Photos" &&
        $name!="Timeline Photos"
    ){

        $show_pictures_link = "photos.php?album_id={$id}&album_name={$name}";

        echo "<div class='col-md-4'>";
            echo "<a href='{$show_pictures_link}'>";
                echo "<img class='img-responsive' style='height:190px;width:190px;' src='https://graph.facebook.com/{$cover_photo}/picture' alt=''>";
            echo "</a>";
            echo "<h3>";
                echo "<a href='{$show_pictures_link}'>{$name}</a>";
            echo "</h3>";

            $count_text="Photo";
            if($count>1){ $count_text="Photos"; }

            echo "<p>";
                echo "<div style='color:#888;'>{$count} {$count_text} / <a href='{$link}' target='_blank'>View on Facebook</a></div>";
                 $description;
            echo "</p>";
        echo "</div>";
    }
}

1 个答案:

答案 0 :(得分:0)

access_token=<your access token>添加到$json_link

例如:

$fb_access_token = "PUT YOUR ACCESS TOKEN HERE" 
$json_link = "http://graph.facebook.com/{$fb_page_id}/albums?access_token={$fb_access_token}&fields=id,name,description,link,cover_photo,count";