コード例 #1
0
 public function testAVideoCanBeAddedToParams()
 {
     $myFile = new FacebookVideo(__DIR__ . '/foo.txt');
     $params = ['name' => 'Foo Bar', 'source' => $myFile];
     $app = new FacebookApp('123', 'foo_secret');
     $request = new FacebookRequest($app, 'foo_token', 'POST', '/foo/videos', $params);
     $actualParams = $request->getParams();
     $this->assertTrue($request->containsFileUploads());
     $this->assertTrue($request->containsVideoUploads());
     $this->assertTrue(!isset($actualParams['source']));
     $this->assertEquals('Foo Bar', $actualParams['name']);
 }
コード例 #2
0
 /**
  * Extracts the files from a request.
  *
  * @param FacebookRequest $request
  *
  * @return string|null
  *
  * @throws FacebookSDKException
  */
 public function extractFileAttachments(FacebookRequest $request)
 {
     if (!$request->containsFileUploads()) {
         return null;
     }
     $files = $request->getFiles();
     $fileNames = [];
     foreach ($files as $file) {
         $fileName = uniqid();
         $this->addFile($fileName, $file);
         $fileNames[] = $fileName;
     }
     $request->resetFiles();
     // @TODO Does Graph support multiple uploads on one endpoint?
     return implode(',', $fileNames);
 }
コード例 #3
0
 /**
  * Prepares the request for sending to the client handler.
  *
  * @param FacebookRequest $request
  *
  * @return array
  */
 public function prepareRequestMessage(FacebookRequest $request)
 {
     $postToVideoUrl = $request->containsVideoUploads();
     $url = $this->getBaseGraphUrl($postToVideoUrl) . $request->getUrl();
     // If we're sending files they should be sent as multipart/form-data
     if ($request->containsFileUploads()) {
         $requestBody = $request->getMultipartBody();
         $request->setHeaders(['Content-Type' => 'multipart/form-data; boundary=' . $requestBody->getBoundary()]);
     } else {
         $requestBody = $request->getUrlEncodedBody();
         $request->setHeaders(['Content-Type' => 'application/x-www-form-urlencoded']);
     }
     return [$url, $request->getMethod(), $request->getHeaders(), $requestBody->getBody()];
 }