How to backend-upload a video to Facebook, but with scheduled publish

时光总嘲笑我的痴心妄想 提交于 2021-01-29 05:00:36

问题


I have a php console script which uploads a video file to my Facebook Page. This works fine (code below). However when this finishes, the video is immediately available publicly. I would like to publish the video at a certain datetime. I couldn't find the proper documentation for this. Is it available anywhere? Alternatively, if I could upload the video available only to me, and then "turn it public", that would suit me also.

<?php
$fb = new Facebook\Facebook([
    'app_id' => '{APPID}',
    'app_secret' => '{APPSECRET}',
    'default_graph_version' => 'v2.10',
]);
$accessToken = '{PERMANENTTOKEN}';



try {
    $videoTitle = 'FOO';
    $videoDescription = 'BAR';
    $data = [
      'title' => $videoTitle,
      'description' => $videoDescription,
    ];
    $basePath = '/path/to/';
    $fileEntry='file.mp4';
  $response = $fb->uploadVideo('{PAGEID}', $basePath.$fileEntry, $data, $accessToken);
} catch(Facebook\Exception\ResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exception\SDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

echo 'Video ID: ' . $response['video_id'];  //this is now publicly available. how can i make it publish at a later date?

回答1:


I think the scheduled_publish_time with the published parameter might work.

$videoTitle = 'FOO';
$videoDescription = 'BAR';
$data = [
  'title' => $videoTitle,
  'description' => $videoDescription,
  'scheduled_publish_time' => strtotime('+7 days'),
  'published' => false,
];

$basePath = '/path/to/';
$fileEntry='file.mp4';
$response = $fb->uploadVideo('{PAGEID}', $basePath.$fileEntry, $data, $accessToken);

scheduled_publish_time Time when this post should go live, this can be any date between ten minutes and six months from the time of the API call.

Possible formats for scheduled_publish_time:

  • An integer UNIX timestamp [in seconds] (e.g. 1530432000).
  • An ISO 8061 timestamp string (e.g. 2018-09-01T10:15:30+01:00).
  • Any string otherwise parsable by PHP's strtotime() (e.g. +2 weeks, tomorrow).

For dates I'm not entirely sure which timezone should be used so maybe will require a bit of experiment.

Links:

  • Video Reference
  • Page Video Reference
  • User Video Reference
  • Not video specific but a similar example of Scheduling Posts for Pages and another one here


来源:https://stackoverflow.com/questions/64365907/how-to-backend-upload-a-video-to-facebook-but-with-scheduled-publish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!