Facebook Ads API: Upload Videos Using the AdVideo Class

Request in PHP using API v2.4

When I try to upload a video using the AdVideo class as shown below,

  $time_limit = ini_get('max_execution_time');
  set_time_limit(0);
  $video = new AdVideo(null, $account_id);
  $video->{AdVideoFields::NAME} = *name*;
  $video->{AdVideoFields::SOURCE} = *video_path*;
 try {
     $video->create();
 } catch (\FacebookAds\Http\Exception\RequestException $e) {
     echo "<script>alert('" . $e->getErrorUserMessage() . "')</script>";
     set_time_limit($time_limit);
     return;
 }
 set_time_limit($time_limit);

      

Result:

I am getting the following exception -
"Operation completed after 60000 milliseconds with 0 bytes received"

The video download is about 20MB and it will take longer to download. How to deal with this? Is there a way to show the download progress? Does this class support batch loading?

Tried set_time_limit (0); but no help.

+3


source to share


1 answer


It looks like you are hitting the CURL timeout which defaults to 60 SDK.

You can use the following code to change the timeout without limit:



Api::instance()
  ->getHttpClient()
  ->getAdapter()
  ->getOpts()
  ->offsetSet(CURLOPT_TIMEOUT, 0);

      

+1


source







All Articles