コード例 #1
0
 /**
  * Upload a video in chunks.
  *
  * @param int $target The id of the target node before the /videos edge.
  * @param string $pathToFile The full path to the file.
  * @param array $metadata The metadata associated with the video file.
  * @param string|null $accessToken The access token.
  * @param int $maxTransferTries The max times to retry a failed upload chunk.
  * @param string|null $graphVersion The Graph API version to use.
  *
  * @return array
  *
  * @throws FacebookSDKException
  */
 public function uploadVideo($target, $pathToFile, $metadata = [], $accessToken = null, $maxTransferTries = 5, $graphVersion = null)
 {
     $accessToken = $accessToken ?: $this->defaultAccessToken;
     $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
     $uploader = new FacebookResumableUploader($this->app, $this->client, $accessToken, $graphVersion);
     $endpoint = '/' . $target . '/videos';
     $file = $this->videoToUpload($pathToFile);
     $chunk = $uploader->start($endpoint, $file);
     do {
         $chunk = $this->maxTriesTransfer($uploader, $endpoint, $chunk, $maxTransferTries);
     } while (!$chunk->isLastChunk());
     return ['video_id' => $chunk->getVideoId(), 'success' => $uploader->finish($endpoint, $chunk->getUploadSessionId(), $metadata)];
 }
コード例 #2
0
 /**
  * @expectedException \Facebook\Exceptions\FacebookResponseException
  */
 public function testStartWillLetErrorResponsesThrow()
 {
     $this->graphApi->failOnStart();
     $uploader = new FacebookResumableUploader($this->fbApp, $this->client, 'access_token', 'v2.4');
     $chunk = $uploader->start('/me/videos', $this->file);
 }