我有一个FB脚本,它在本地工作正常,但它不在线。 第一个脚本是事件的een脚本,第二个脚本是获取Facebook专辑。
<?php
$fb_page_id = "408403535882715";
$access_token = "Acces_token";
$year_range = 10;
$since_date = date('Y-01-01', strtotime('-' . $year_range . ' years'));
$until_date = date('Y-01-01', strtotime('+' . $year_range . ' years'));
// unix timestamp years
$since_unix_timestamp = strtotime(date("Y-m-d"));
$until_unix_timestamp = strtotime($until_date);
$fields="id,name,description,location,venue,timezone,start_time,cover";
$json_link = "https://graph.facebook.com/{$fb_page_id}/events/feed/?fields={$fields}&access_token={$access_token}&since={$since_unix_timestamp}&until={$until_unix_timestamp}";
$json = file_get_contents($json_link);
$obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
// count the number of events
$event_count = count($obj['data']);
for($x=0; $x<$event_count; $x++){
if($x<1) {
$start_date = date( 'l, F d, Y', strtotime($obj['data'][$x]['start_time']));
$start_time = date('H:i', strtotime($obj['data'][$x]['start_time']) - 60 * 60 * 23);
$pic_big = isset($obj['data'][$x]['cover']['source']) ? $obj['data'][$x]['cover']['source'] : "https://graph.facebook.com/{$fb_page_id}/picture?type=large";
$eid = $obj['data'][$x]['id'];
$name = $obj['data'][$x]['name'];
$location = isset($obj['data'][$x]['location']) ? $obj['data'][$x]['location'] : "";
$description = isset($obj['data'][$x]['description']) ? $obj['data'][$x]['description'] : "";
echo "<div class='eventFrontpage'";
echo "<div class='info'>";
echo "<h1>{$name}</h1>";
echo "<span class='datum'>{$start_date} om {$start_time} uur</span></br>";
echo "<span class='locatie'>Locatie: {$location}</span></br>";
echo "<span class='content'>Info: {$description}</span></br>";
echo "</div>";
echo "</div>";
break;
}
}
?>
和这一个(在不同的页面上)
<?php
$fb_page_id = "408403535882715";
$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" &&
$name!="Mobile Uploads"
){
$show_pictures_link = "photos.php?album_id={$id}&album_name={$name}";
echo "<a class='mediaAlbum {$name}' href='{$link}' target='_blank'>";
echo "<img class='img-responsive' src='http://graph.facebook.com/{$cover_photo}/picture' alt=''>";
echo "<h2>{$name}</h2>";
echo "</a>";
}
}
?>
有人有想法吗?
答案 0 :(得分:0)
答案:因为它是PHP&lt; 5.4在我的服务器上de代码需要翻译:
$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);