Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. Api::init($APP_ID,$APP_SECRET,$ACCESS_TOKEN);
  2.  
  3. $user = new AdAccount($account_id);
  4.  
  5.  
  6. use FacebookAdsObjectFieldsAdImageFields;
  7. define('SDK_DIR',__DIR__.'\');
  8. echo "The image is: ".SDK_DIR.$ImagePath. "<br>";
  9. try {
  10. $image = new AdImage(null, $account_id);
  11. $image->{AdImageFields::FILENAME} = SDK_DIR.$ImagePath;
  12. $image->save();
  13.  
  14. $imageHash = $image->{AdImageFields::HASH}.PHP_EOL;
  15.  
  16. echo 'Image Hash: '.$imageHash . "<br>";
  17.  
  18.  
  19.  
  20. echo 'version:1'."<br>";
  21. $creative = $user->createAdCreative(
  22. array(), //create an ad creative for general use to our ads
  23. array(
  24. AdCreativeFields::NAME => $AdNameCreative,
  25. AdCreativeFields::TITLE => $AdTitleCreative,
  26. AdCreativeFields::BODY => $BodyAdCreative,
  27. AdCreativeFields::IMAGE_HASH => $imageHash,
  28. AdCreativeFields::OBJECT_URL => $UrlCreative,
  29. )
  30. );
  31. } catch (FacebookAdsExceptionException $e) {
  32. echo 'GenelralExxception: ' . $e->getMessage();
  33. echo 'GeneralExceptiontype:'. $e->getCode();
  34. echo 'typeException:' . var_dump($e);
  35. // echo 'the sub code is: ' . $e->getSubErrorCode();
  36. //$previousException = $e->getPrevious();
  37. // Do some further processing on $previousException
  38. exit;
  39. }catch (FacebookAdsHttpExceptionEmptyResponseException $e) {
  40. echo 'Message: ' . $e->getMessage();
  41. echo 'Type:'. var_dump($e);
  42. //$previousException = $e->getPrevious();
  43. // Do some further processing on $previousException
  44. exit;
  45. }catch (FacebookAdsHttpExceptionAuthorizationException $e) {
  46.  
  47. echo 'AuthorizationException: ' . $e->getMessage()."<br>";
  48. echo 'AuthorizationExceptiontype:'. $e->getCode()."<br>";
  49. echo 'typeAuthorization:' . var_dump($e);
  50. //$previousException = $e->getPrevious();
  51. // Do some further processing on $previousException
  52. print_r($e);
  53. exit;
  54. }
  55.  
  56.  
  57. $creativeId = $creative->id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement