2013-06-24 38 views
5

Tôi đã sử dụng mã sau. Nó hoạt động tốt mà không có 'scheduled_publish_time', nếu không tôi nhận được lỗi này "(# 100) Bạn không thể chỉ định thời gian xuất bản theo lịch trình trên bài đăng đã xuất bản". Trước đây tôi đã đăng ký ứng dụng của mình với một đoạn mã khác. Nó rất kì lạ.Lỗi 100 lập lịch bài đăng trên Facebook Page

include_once("inc/facebook.php"); //include facebook SDK 

$appId = '21xxxxxxxxxxx'; //Facebook App ID 
$appSecret = '6b8f4bxxxxxxxxxxxxxd56'; // Facebook App Secret 
$return_url = 'http://localhost:8888/...'; //return url (url to script) 
$homeurl = 'http://localhost:8888/...'; //return to home 
$fbPermissions = 'publish_stream,manage_pages'; //Required facebook permissions 

//Call Facebook API 
$facebook = new Facebook(array(
    'appId' => $appId, 
    'secret' => $appSecret, 
    'cookie' => true, 
    'fileUpload' => true 
)); 

    $accounts = $facebook->api('/me/accounts'); 
$PAGE_ID = get_option('fb_post_cron_page'); // it is an option saved in WordPress 

foreach($accounts['data'] as $account){ 
    if($account['id'] == $PAGE_ID){ 
    $ACCESS_TOKEN = $account['access_token']; 
    } 
} 

$post_url = '/'.$PAGE_ID.'/photos'; 
$upload_dir = wp_upload_dir(); 
$upload_dir= $upload_dir['path']; 


$timezone= 'Europe/Rome'; 
$date = new DateTime($dateStr, new DateTimeZone($timezone)); 

//posts message on page statues 
$args = array(
    'access_token' => $ACCESS_TOKEN, 
    'source' => '@' . $image_abs_path, 
    'message' => $post_message, 
    'published' => true, 
    'scheduled_publish_time' => $date->getTimestamp() 
); 

try { 
    $postResult = $facebook->api($post_url, 'post', $args); 
} catch (FacebookApiException $e) { 
    echo $e->getMessage(); 
} 

Trả lời

8

bạn phải thiết lập 'công bố' false

$args = array(
    'access_token' => $ACCESS_TOKEN, 
    'source' => '@' . $image_abs_path, 
    'message' => $post_message, 
    'published' => false, 
    'scheduled_publish_time' => $date->getTimestamp() 
);