facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.17k stars 1.95k forks source link

Video Upload With Url #1181

Closed tnduc closed 4 years ago

tnduc commented 4 years ago
$fb = new Facebook\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.10',
  ]);

$data = [
  'title' => 'My Foo Video',
  'description' => 'This video is full of foo and bar action.',
];

try {
  $response = $fb->uploadVideo('{page-id}/videos', 'http://xxx/video.mp4', $data, '{user-access-token}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

echo 'Video ID: ' . $response['video_id'];

Error: filesize(): stat failed for xxx

alielmajdaoui commented 4 years ago

I came across this error today and got it fixed.

The problem is filesize() get the size of a remote file, alternatively, we can do it with curl to get its size.

The fix: https://github.com/p4rse/php-graph-sdk/commit/8ae3f00a73579b409f171a0fd4ff41416c8e80fa