An SDK built to facilitate application development for Facebook Ads API.

Overview

Facebook Business SDK for PHP

Packagist License Build Status Scrutinizer Scrutinizer Coverage

Introduction

The Facebook Business SDK is a one-stop shop to help our partners better serve their businesses. Partners are using multiple Facebook API's to server the needs of their clients. Adopting all these API's and keeping them up to date across the various platforms can be time consuming and ultimately prohibitive. For this reason Facebook has developed the Business SDK bundling many of its APIs into one SDK to ease implementation and upkeep. The Business SDK is an upgraded version of the Marketing API SDK that includes the Marketing API as well as many Facebook APIs from different platforms such as Pages, Business Manager, Instagram, etc.

Quick Start

Business SDK Getting Started Guide

Pre-requisites

Register An App

To get started with the SDK, you must have an app registered on developers.facebook.com.

To manage the Marketing API, please visit your App Dashboard and add the Marketing API product to your app.

IMPORTANT: For security, it is recommended that you turn on 'App Secret Proof for Server API calls' in your app's Settings->Advanced page.

Obtain An Access Token

When someone connects with an app using Facebook Login and approves the request for permissions, the app obtains an access token that provides temporary, secure access to Facebook APIs.

An access token is an opaque string that identifies a User, app, or Page.

For example, to access the Marketing API, you need to generate a User access token for your app and ask for the ads_management permission; to access Pages API, you need to generate a Page access token for your app and ask for the manage_page permission.

Refer to our Access Token Guide to learn more.

For now, we can use the Graph Explorer to get an access token.

Installation

The Facebook Business SDK requires PHP 5.6 or greater.

Composer

The Facebook Business SDK uses composer to manage dependencies. Visit the composer documentation to learn how to install composer.

Add the following to your composer.json file:

{
    "require": {
        "facebook/php-business-sdk": "5.0.5"
    }
}

then install it through composer:

php composer.phar install --no-dev

This SDK and its dependencies will be installed under ./vendor.

Alternatives

This repository is written following the psr-4 autoloading standard. Any psr-4 compatible autoloader can be used.

Usage

Api main class

The FacebookAds\Api object is the foundation of the Business SDK which encapsulates a FacebookAds\Session and is used to execute requests against the Graph API.

To instantiate an Api object you will need a valid access token:

use FacebookAds\Api;

// Initialize a new Session and instantiate an Api object
Api::init($app_id, $app_secret, $access_token);

// The Api object is now available through singleton
$api = Api::instance();

Once instantiated, the Api object will allow you to start making requests to the Graph API.

Fields names

Due to the high number of field names in the Graph API existing objects, in order to facilitate your code maintainability, enum-like classes are provided. These files are stored under the FacebookAds/Object/Fields directory. You can access object properties in the same manner you would usually do in php:

use FacebookAds\Object\AdAccount;

$account = new AdAccount();
$account->name = 'My account name';
echo $account->name;

or using the enums:

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;

$account = new AdAccount();
$account->{AdAccountFields::NAME} = 'My account name';
echo $account->{AdAccountFields::NAME};

Object classes

Facebook Ads entities are defined as classes under the FacebookAds/Object directory.

Read Objects

use FacebookAds\Object\AdAccount;

$account = (new AdAccount($account_id))->getSelf();

For some objects, the Ads API doesn't return all available fields by default. The first argument of the object's read method is an array of field names to be requested.

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;

$fields = array(
  AdAccountFields::ID,
  AdAccountFields::NAME,
);

$account = (new AdAccount($account_id))->getSelf($fields);

Requesting an high number of fields may cause the response time to visibly increase, you should always request only the fields you really need.

Create Objects

use FacebookAds\Object\AdSet;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdSetFields;

$account_id = 'act_123123';
$campaign_id = '123456';

$account = new AdAccount($account_id);
$adset = $account->createAdSet(
    array(),
    array(
      AdSetFields::NAME => 'My Test AdSet',
      AdSetFields::CAMPAIGN_ID => campaign_id,
      AdSetFields::DAILY_BUDGET => 150,
      AdSetFields::START_TIME => (new \DateTime("+1 week"))->format(\DateTime::ISO8601),
      AdSetFields::END_TIME => (new \DateTime("+2 week"))->format(\DateTime::ISO8601),
      AdSetFields::BILLING_EVENT => 'IMPRESSIONS',
      AdSetFields::TARGETING => array('geo_locations' => array('countries' => array('US'))),
      AdSetFields::BID_AMOUNT => '1000',
    )
);

echo $adset->id;

Update Objects

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;

$ad_set_id = '123456';

$set = new AdSet($ad_set_id);
$fields = array(
);
$params = array(
  AdSetFields::NAME => 'My new AdSet name',
);
$set->updateSelf($fields, $params);

Delete Objects

use FacebookAds\Object\AdSet;

$ad_set_id = '123456';

$set = new AdSet($ad_set_id);
$set->deleteSelf();

Cursors

Since the release of the Facebook Graph API 2.0, pagination is handled through cursors. Here cursors are defined as in \FacebookAds\Cursor. Cursors are generally returned from connection methods:

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\CampaignFields;

$account = new AdAccount('<ACT_ID>');
$cursor = $account->getCampaigns(['id','name']);

// Loop over objects
foreach ($cursor as $campaign) {
  echo $campaign->{CampaignFields::NAME}.PHP_EOL;
}

// Access objects by index
if ($cursor->count() > 0) {
  echo "The first campaign in the cursor is: ".$cursor[0]->{CampaignFields::NAME}.PHP_EOL;
}

// Fetch the next page
$cursor->fetchAfter();
// New Objects will be appended to the cursor

Implicit Fetching

Whenever all object connected to a parent are required (carelessly from the number of HTTP requests) implicit fetching can help reducing the amount of code required. If cursor has Implicit Fetching enabled, while iterating (foreach, Cursor::next(), Cursor::prev()) the page end is reached, the SDK will automatically fetch and append a new page, until cursor end. Implicit Fetching will make you lose control of the number of HTTP request that will be sent and, for this reason, is disabled by default. Implicit Fetching can be enabled for a specific cursor:

$cursor->setUseImplicitFetch(true);

Or globally:

use FacebookAds\Cursor;

Cursor::setDefaultUseImplicitFetch(true);

Reverse Iterations

Cursors are bi-directional, and can be iterated in reverse order:

use FacebookAds\Object\AbstractCrudObject;

/** @var \FacebookAds\Cursor $cursor */
$cursor->setUseImplicitFetch(true);

$cursor->end();
while ($cursor->valid()) {
  echo $cursor->current()->{AbstractCrudObject::FIELD_ID}.PHP_EOL;
  $cursor->prev();
}

Tests

The 'test' folder contains the test cases. These are logically divided in unit and integration tests. Integration tests require an active Facebook Ad Account, a Facebook Application and a valid Access Token.

Note: we are currently unable to securely and reliably run integration tests on a public CI system. Our integrations with Travis and Scrutinizer (including badges at the top of this file) include only unit tests.

Install dependencies

From the root folder run:

php composer.phar install --dev

Execute unit tests only

./vendor/bin/phpunit -c test/phpunit-travis.xml

To run tests individually (be sure not to be pointing to an integration test file):

./vendor/bin/phpunit -c test/phpunit-travis.xml path/to/class/file

Execute all tests (unit + integration)

Setup your integration config:

1 - Copy the config file template.

cp test/config.php.dist test/config.php

2 - Edit test/config.php with your informations.

Execute:

./vendor/bin/phpunit -c test/

To run tests individually:

./vendor/bin/phpunit -c test/ path/to/class/file

Debug

If this SDK is not working as expected, it may be either a SDK issue or API issue.

This can be identified by constructing a raw cURL request and seeing if the response is as expected

for example:

require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Object\AdAccount;

Api::init($app_id, $app_secret, $access_token);
$api = Api::instance();

use FacebookAds\Logger\CurlLogger;
$api->setLogger(new CurlLogger());
$account = new AdAccount($account_id);
$account->read(array('id'));

When running this code, this cURL request will be printed to the console as:

curl -G \
  -d 'fields=id' \
  -d 'access_token=<access_token>' \
  https://graph.facebook.com/v3.1/<act_accountid>

SDK Codegen

Our SDK is autogenerated from SDK Codegen. If you want to learn more about how our SDK code is generated, please check this repository.

Issue

Since we want to handle bugs more efficiently, we've decided to close issue reporting in Github and move to our dedicated bug reporting channel. If you encounter a bug with Business SDK (PHP), please report the issue at our developer bug reporting channel.

Comments
  • Custom Audience Triggers Empty Response Exception

    Custom Audience Triggers Empty Response Exception

    I'm attempting to create a custom audience based on the sample code at https://developers.facebook.com/docs/marketing-api/lookalike-audience-targeting/v2.5#create

    My Code

    $fb_custom_audience = new CustomAudience( null, 'act_<REMOVED>' );
    
    $fb_custom_audience->setData(array(
            CustomAudienceFields::NAME => 'My lookalike audience',
            CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::LOOKALIKE,
            CustomAudienceFields::ORIGIN_AUDIENCE_ID => '<REMOVED>',
            CustomAudienceFields::LOOKALIKE_SPEC => array(
            'type' => 'similarity',
            'country' => 'US',
        ),
    ));
    $fb_custom_audience->create();
    

    The origin_audience_id I'm using has an approximate_count of 20 which should trigger a "Source Audience is Too Small" exception but it throws a EmptyResponseException instead.

    opened by JordanDalton 17
  • i got a error  Undefined class constant 'BURGER'

    i got a error Undefined class constant 'BURGER'

    Hi, I am integrating Facebook ads sdk into my Linux server. For your guidance i install all packages into my server. when i execute

    ./vendor/bin/phpunit -c test/

    This comment i got a error first. xdebug not found error. so i install xdebug into server then i add into composer.json file.

    Next i run the following comment

    ./vendor/bin/phpunit -c test/

    i got the error again.

    My error is given below

    E....EEEEEEEEEEEE.EEPHP Fatal error: Undefined class constant 'BURGER' in /var/www/facebook-php-ads-sdk/test/FacebookAdsTest/Object/ReachFrequencyPredictionTest.php on line 49 PHP Stack trace: PHP 1. {main}() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/phpunit:56 PHP 3. PHPUnit_TextUI_Command->run() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/TextUI/Command.php:138 PHP 4. PHPUnit_TextUI_TestRunner->doRun() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/TextUI/Command.php:186 PHP 5. PHPUnit_Framework_TestSuite->run() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:423 PHP 6. PHPUnit_Framework_TestSuite->run() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751 PHP 7. PHPUnit_Framework_TestCase->run() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751 PHP 8. PHPUnit_Framework_TestResult->run() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestCase.php:708 PHP 9. PHPUnit_Framework_TestCase->runBare() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestResult.php:643 PHP 10. PHPUnit_Framework_TestCase->runTest() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestCase.php:772 PHP 11. ReflectionMethod->invokeArgs() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestCase.php:906 PHP 12. FacebookAdsTest\Object\ReachFrequencyPredictionTest->testCrudAccess() /var/www/facebook-php-ads-sdk/vendor/phpunit/phpunit/src/Framework/TestCase.php:906 root@Devel-56:/var/www/facebook-php-ads-sdk# vim /var/www/facebook-php-ads-sdk/test/FacebookAdsTest/Object/ReachFrequencyPredictionTest.php root@Devel-56:/var/www/facebook-php-ads-sdk# ./vendor/bin/phpunit -c test/ PHPUnit 4.3.1 by Sebastian Bergmann

    Please help me whats wrong please any one help me

    Fatal error: Undefined class constant 'BURGER' in /var/www/facebook-php-ads-sdk/test/FacebookAdsTest/Object/ReachFrequencyPredictionTest.php on line 49

    opened by Nathan-Srivi 17
  • getInsightsAsync() and getInsights() return different results

    getInsightsAsync() and getInsights() return different results

    For a given campaign, I want to return the insights. For this, I used same $fields and $params arrays for getInsights() und getInsightsAsync():

        $fields = array(
          InsightsFields::CAMPAIGN_NAME,
          InsightsFields::CAMPAIGN_ID,
          InsightsFields::DATE_START,
          InsightsFields::DATE_STOP,
          InsightsFields::IMPRESSIONS,
          InsightsFields::SOCIAL_IMPRESSIONS,
          InsightsFields::UNIQUE_CLICKS,
          InsightsFields::REACH,
          InsightsFields::SPEND,
          InsightsFields::TOTAL_ACTIONS,
          InsightsFields::TOTAL_ACTION_VALUE,
          InsightsFields::ACTIONS
        );
        $params = array(
          'time_range' => array(
            'since' => '2013-01-01',
            'until' => '2016-02-06',
          ),
          'level' => InsightsLevels::CAMPAIGN,
        );
    

    Here's the code for getInsights():

      $campaign->getInsights($fields, $params);
    

    This returned NOT EMPTY values for

    • name,
    • reach,
    • amount spent,
    • unique clicks
    • impressions

    But it also returned EMPTY values for

    • frequency
    • call to action clicks
    • inline link clicks
    • social clicks
    • unique social clicks
    • ctr
    • cpm

    Here my code for the asynchronous call:

      $async_job = $campaign->getInsightsAsync($fields, $params);
        $async_job->read();
        while (!$async_job->isComplete()) {
          sleep(13);
          $async_job->read();
        }
        return $async_job->getResult();
    

    This returns additionaly the following NOT EMPTY fields:

    • frequency
    • call to action clicks
    • inline link clicks
    • social clicks
    • unique social clicks
    • ctr
    • cpm

    But, here the following field is empty:

    • campaign name

    Am I doing something wrong or is there an issue? Additionally, how can I get values for Delivery, Results, Cost and cpc? Is this possible by the ads sdk? In business ads manager, I can get these values in a table.

    Regards, Benjamin Schäfer

    opened by benjamin-schaefer 13
  • error when creating custom audience

    error when creating custom audience

    The code:

    use \FacebookAds\Api;
    use \FacebookAds\Object\CustomAudience;
    use \FacebookAds\Object\Fields\CustomAudienceFields;
    
    Api::init($app_id, $app_secret, $access_token);
    
    $audience = new CustomAudience(null, $account_id);
    $audience->setData(array(
        CustomAudienceFields::NAME => 'test',
        CustomAudienceFields::DESCRIPTION => 'test',
        CustomAudienceFields::DATA_SOURCE => array('EVENT_BASED' => 'WEB_PIXEL_HITS'),
    ));
    $audience->create();
    

    The error:

    (#2655) Terms of service has not been accepted
    

    I have 2 questions:

    1. How do I agree to the terms of service? When I create a custom audience through the web interface there is a checkbox each time I create one.
    2. Am I setting the DATA_SOURCE correctly? I want an audience based on hits to a single page. The code I used is based of the docs here, but there is no clear example for the specific scenario I want: https://developers.facebook.com/docs/reference/ads-api/custom-audience-targeting/#data_source
    opened by cornernote 13
  • Uncaught exception 'FacebookAds\Http\Exception\ServerException'

    Uncaught exception 'FacebookAds\Http\Exception\ServerException'

    PHP SDK version : 2.10.* I have a script which pulls campaign insights and most of the time scripts works perfectly but sometime it fails with throwing exception:

    PHP Fatal error: Uncaught exception 'FacebookAds\Http\Exception\ServerException' with message 'An unknown error occurred' in /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Exception/RequestException.php:147 Stack trace: #0 /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/Api.php(162): FacebookAds\Http\Request->execute() #3 /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/Api.php(204): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/ApiRequest.php(183): FacebookAds\Api->call('/*******account - id ******/...', 'GET', Array, Array) #5 /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds in /var/app/current/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Exception/RequestException.php on line 147

    opened by sachinsinghshekhawat 12
  •  Invalid appsecret_proof provided in the API argument????

    Invalid appsecret_proof provided in the API argument????

    Hi, I have completed the facebook php ads sdk installation in my server. I got the following error " Invalid appsecret_proof provided in the API argument????",

    while executing this ./vendor/bin/phpunit -c test/. So, please advice us to fix this issue.

    API Support 
    opened by Nathan-Srivi 12
  • help with FacebookPermissionException

    help with FacebookPermissionException

    Hello,

    I am getting this error:

    Facebook\FacebookPermissionException (#294) Managing advertisements requires the extended permission ads_management and an application that is whitelisted to access the Ads API

    I'm not sure what to try or who to contact. Any help would be greatly appreciated.

    opened by cornernote 12
  • (#2654) Unsupported operator: The operator operator is not supported

    (#2654) Unsupported operator: The operator operator is not supported

    I am trying to create a custom audience by the example in "https://developers.facebook.com/docs/marketing-api/audiences-api/websites#audiencerules" with no luck. I get the error "(#2654) Unsupported operator: The operator operator is not supported"

    $params= [
                CustomAudienceFields::NAME           => $name . ' Tobi custom audience.',
                CustomAudienceFields::SUBTYPE        => 'WEBSITE',
                CustomAudienceFields::RETENTION_DAYS => 14,
                CustomAudienceFields::RULE           => [
                    'inclusions' => [
                        'operator' => 'or',
                        'rules'    => [
                            [
                                'event_sources'     => [
                                    [
                                        'id'   => $pixelId,
                                        'type' => 'pixel',
                                    ],
                                ],
                                'retention_seconds' => 1209600,
                                'filter'            => [
                                    'operator' => 'and',
                                    'filters'  => [
                                        [
                                            'field'    => 'event',
                                            'operator' => 'i_contains',
                                            'value'    => 'AddToCart',
                                        ],
                                        [
                                            'field'    => 'event',
                                            'operator' => 'i_not_contains',
                                            'value'    => 'Purchase',
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
                CustomAudienceFields::PREFILL        => '1',
                CustomAudienceFields::PIXEL_ID       => $pixelId,
            ];
    
            try {
                $audience = (new CustomAudience(null, 'act_' . $adAccountId));
    
                dd($audience->create($params));
            } catch (AuthorizationException $e) {
                print_r($e->getMessage());
                dd($e->getErrorUserMessage());
            }`
    
    opened by elygiux 11
  • Error during create Ad

    Error during create Ad

    Good day, i'm trying to run the example "adgroup_creation.php" included in this last version (2.5) but i get many errors. The first is when i try to set "CampaignFields::STATUS" because it seems this constant doesn't exists so i have to replace with "effective_status". The same problem i have when i try to set "AdSetFields::STATUS".

    But the big problems arrive now. I'm trying to create AdSet using geolocation and i use this code:

    $dato = array( 'access_token' => $access_token, 'q' => "Siena", 'type' => 'adgeolocation', 'location_types' => "['city']" );

    $http = new HTTPProxy(); $citta_str = $http->connect("https://graph.facebook.com/v2.5/search", $dato, "GET"); $citta_vet = json_decode($citta_str, true); $key_city=""; if(count($citta_vet['data']) > 0) { $citta_vet=$citta_vet['data'][0]; $key_city=$citta_vet['key']; $targeting = new TargetingSpecs(); $radius="20"; $vett_to_send=array('key'=>$key_city, 'radius'=>$radius,'distance_unit'=>'kilometer'); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('IT'), 'cities' => $vett_to_send); }

    $adset = new AdSet(null, $account->id); $adset->setData(array( AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_ID => $campaign->id, effective_status => AdSet::STATUS_ACTIVE, AdSetFields::DAILY_BUDGET => '150', AdSetFields::TARGETING => $targeting, AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 2, AdSetFields::START_TIME => (new \DateTime("+1 week"))->format(\DateTime::ISO8601), AdSetFields::END_TIME => (new \DateTime("+2 week"))->format(\DateTime::ISO8601), ));

    $adset->validate()->create();

    but in creation step, i get this error: [22-Dec-2015 12:19:46 Europe/Berlin] PHP Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Exception/RequestException.php:137 Stack trace: #0 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Client.php(216): FacebookAds\Http\Exception\RequestException::create(Array, 500) #1 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Api.php(152): FacebookAds\Http\Request->execute() #3 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Api.php(194): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Object/AbstractCrudObject.php(236): FacebookAds\Api->call('/act_35434324/a... in /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Exception/RequestException.php on line 137

    It works if i search by interest as in the example file.

    The other problem i have is related to the "step 7"

    $ad = new Ad(null, $account->id); $ad->setData(array( AdFields::CREATIVE => array('creative_id' => $creative->id), AdFields::NAME => 'My First Ad', AdFields::ADSET_ID => $adset->id, )); $ad->create();

    Even here i get here i get this error

    [22-Dec-2015 12:26:59 Europe/Berlin] PHP Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Exception/RequestException.php:137 Stack trace: #0 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Client.php(216): FacebookAds\Http\Exception\RequestException::create(Array, 500) #1 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Api.php(152): FacebookAds\Http\Request->execute() #3 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Api.php(194): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Object/AbstractCrudObject.php(236): FacebookAds\Api->call('/act_35434324/a... in /var/www/test/api/facebook/facebook-php-ads-sdk-master_new/src/FacebookAds/Http/Exception/RequestException.php on line 137

    Can i solve these problems in some ways? Could you help me? Thanks

    opened by AcidS76 11
  • Can I create a AdCreative duplicate?

    Can I create a AdCreative duplicate?

    I have AdCreative.

    How do I create a duplicate using the SDK? Read existing AdCreative and create new AdCreative using old params - not a good idea. Is there a better option?

    opened by Mirko09 11
  • Resolve PHP 8.1 Deprecations

    Resolve PHP 8.1 Deprecations

    This resolves php 8.1 deprecations in a backwards compatible way.

    More ideally, return types should be added to function definitions, but this would no longer support PHP 5.6 as described in the README. If the team is open to bumping up version requirements to only include supported PHP versions (7.4+), I can revisit this to add return types instead.

    CLA Signed 
    opened by natewiebe13 10
  • Move S2S tests to codegen excluded folder

    Move S2S tests to codegen excluded folder

    Summary:

    • removed codegen duplicate of test
    • created ServerSide folder and moved test into it so that codegen script will ignore it

    Reviewed By: HeyMultiverse

    Differential Revision: D20688618

    CLA Signed fb-exported 
    opened by davit-y 1
Releases(3.0.0)
  • 2.10.1(Jul 18, 2017)

  • 2.8.1(Oct 6, 2016)

    New Features

    • Instant Articles is now a separate ads placement, so that advertisers can enable or disable showing ads in Instant Articles. This new placement options is under /ACCOUNT_ID/adsets and /AD_SET_ID. See Targeting Specs. If you use this placement you must also select feed as a position and for device_platforms select mobile since Instant Articles is for mobile only.
    • Facebook Offers is redesigned and is easier for people to save and redeem your offer from any device. If they don't use your offer, they'll get notifications about it before it expires. To use the API to create offers:
      • Use /nativeoffers as an endpoint. The endpoint /offers is associated with the old product and has been deprecated.
      • Use offer_id in the promoted_object for an ad set.
      • To learn more see Offer Ads and Page Native Offers.

    Breaking Changes

    ** Please Review These Changes

    Ads Management

    • As of 2.8, Website Custom Audiences now only allow at most 200 comparisons in the rule. The number of comparisons are the number of comparison operators in the rule.
    • The place_page_set_id field under Ad creative is now optional for versions v2.7 and v2.6 and has been deprecated in v2.8. See Ad Creative.
    • offer_data under link_data for an ad object has been deprecated.
    • The ad account group endpoints AdAccountGroup have been deprecated. To manage Ad Accounts, you should use Business Manager or Business Manager API with business_management extended permission.
    • The edge AD_ACCOUNT/audiences has been deprecated.
    • The ad_object_by_url field for /search in Ad Targeting Search has been deprecated.
    • The fields actor_id, actor_image_hash, actor_image_url, and actor_name have been deprecated from ad creative GET.

    Ads Insights

    • We deprecated the redundant fields and parameters in /insights endpoint. In earlier releases it supported the params: fields,summary, default_summary, filtering and sort. However/insights should always exactly return what you queried in the POST requests.
    • In earlier releases we will display all valid fields for /insights if you provided an invalid field as a parameter. We now send an the error message which points to a list of valid fields.
    • In the past we inconsistently returned /insights fields in a variety of types: some fields were string such as impressions, some were numericstring, and some were float. We now return all numeric fields, including float as numericstring. All floating point numbers will maintain six precision points.
    • The insights metric post_like in the actions field is now named post_reaction, see Ads Action Stats. This is more consistent with naming in user interfaces.

    Business Manager

    The owner_business field has been deprecated and no longer exists for objects connected to a business, including Ad accounts, Ad Campaign, Product Catalog, and Instagram User.

    Source code(tar.gz)
    Source code(zip)
  • 2.7.1(Jul 14, 2016)

    This is a new major release, which diverges in behavior from the previous one. Please review these changes:

    • Edges from an object now return a Cursor: To equalize the behavior of edges, now all edges from an object return a Cursor. In the past there were exceptions to this rule, e.g.: AdAccount::getReachEstimate used to return a ReachEstimate.
    • New Daily Budget Limits: We changed the logic around ads delivery which impacts the interpretation of the daily ad budget limits. Starting from v2.7, you may be charged up to 125% of your daily budget. For example, if your daily budget is $10, you may be charged up to $12.50. However, your weekly spend will NOT exceed 7 times the daily amount, or $70 in this example. We will prorate this for partial weeks. More details Ad Set Budget.
    • Lifetime Budgets and New Daily Budgets: Also, starting with v2.7, you can no longer edit ad sets created with the new daily budget controls to use lifetime budgets. Similarly you can no longer edit lifetime budgets to use the new daily budget controls.
    • Ad Placements Update: We have improvements to our design of placement, so that advertisers can more easily identify and select placement options that will serve them best. Instead of having platform as the only dimension, advertisers can select placements across different dimensions, such as device type including desktop or mobile, publisher such as facebook, instagram, or audience_network, and placements of each publisher. Only Facebook has multiple placements currently. The field page_types will still be included in read results, but cannot be used to create or update placements in v2.7. More details in Targeting Spec.
    • Insights Placement Updates: As a related change, on the /insights endpoints, we’ll introduce two new breakdowns options: publisher_platform and platform_position. Along with the existing impression_device breakdown, you can get performance metrics with these placement dimensions. See Insights Breakdowns for more details.
    • Ad Creative Update: With 2.7 object_story_id will be null for an ad creative created with an object_story_spec. The effective_object_story_id will always be the object_story_id regardless of object_story_spec. More details in Ad Creative.
    • Insights Integer Field: For Insights API, integer values were too big and overflowed with int32. We changed all int32 field values into numeric strings to keep consistent with other Marketing API fields with currency values. For v2.7 onward, numeric values in int32 will be quoted in responses. For v2.5 for backwards compatibility, numeric values in int32 will be shown as a number. More details in Ads Insights.
    Source code(tar.gz)
    Source code(zip)
  • 2.6.0(Apr 12, 2016)

    This is a new major release, which diverges in behavior from the previous one. Please review these changes:

    • Deprecated the connectionobjects API
    • Deprecated max_product_count for DPA creatives. In order to opt-out of Carousel format, specify force_single_link=true.
    • Deprecated product_ad_behavior field at the Ad Set level
    • For /insights objects the fields parameter no longer accepts breakdowns. Now you should specified this in 'breakdowns' parameter in query. This includes: age, country, gender, frequency_value,hourly_stats_aggregated_by_advertiser_time_zone, hourly_stats_aggregated_by_audience_time_zone, impression_device, place_page_id, placement, product_id, and region
    • Reduced scope of AuthorizationException, it should only throw now for errors that have to do with Authorization. Some errors that previously were AuthorizationException may become RequestException
    • RequestException now has a single ResponseInterface param in constructor
    Source code(tar.gz)
    Source code(zip)
  • 2.5.2(Apr 9, 2016)

  • 2.5.1(Nov 6, 2015)

  • 2.5.0(Oct 8, 2015)

    • Comply with Facebook Graph API v2.5.
      • Notably the object renaming is the big change: https://github.com/facebook/facebook-php-ads-sdk/commit/225ed62295a203c3ce30b7be3f6eb890eced3f90
    • Reading remote fields that are not statically declared won't cause an exception to be thrown
    • Add support for VideoThumbnails object
    • Various bugfix
    Source code(tar.gz)
    Source code(zip)
  • 2.4.2(Sep 4, 2015)

  • 2.4.1(Aug 12, 2015)

  • 2.4.0(Jul 10, 2015)

    • Comply with API v2.4 changes: https://developers.facebook.com/docs/marketing-api/changelog#v2_4
    • Add support for Business Manager API
    • Refactor AdAccountGroupAccount interface to align with AdAccountGroupUser: https://github.com/facebook/facebook-php-ads-sdk/commit/dffd6f33c6a2987ff26a1acd0df36eb59f53465d
    • Refactor Fields and Values "Enum-like" classes to provide names and values exportability and validation. Centralize object fields declaration to enums: https://github.com/facebook/facebook-php-ads-sdk/commit/a59729c048c2653fa40132bc85a2f40ed67d835f
    Source code(tar.gz)
    Source code(zip)
  • 2.3.1(May 4, 2015)

    • Cursor now supports offset based pagination
    • Add support for creative sequencing
    • Add support for Call Now CTA
    • Add an utility script to create PHAR archives of the SDK
    • Additional bug fixes and missing fields
    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Mar 25, 2015)

  • 2.2.4(Mar 6, 2015)

  • 2.2.3(Dec 19, 2014)

    • support for validate_only
    • Added thumbnail_url, thumbnail_width, thumbnail_height to AdCreative
    • Add RequestException support for advanced error messaging
    • Update examples and tests to support AdSet->bid_info
    Source code(tar.gz)
    Source code(zip)
  • 2.2.2(Nov 19, 2014)

    • Bugfix
      • Fixes an issue that prevented cursors from implicitly fetching next pages of data
      • Fixes an issue that prevented searching using TargetingSearch from returning a valid Cursor
    Source code(tar.gz)
    Source code(zip)
  • 2.2.1(Nov 4, 2014)

  • 2.2.0(Oct 31, 2014)

    • Align versioning with AdsAPI
    • Remove facebook/php-sdk-v4 and psr/log dependencies
      • Simplify initialization
    • Provide bundled Http layer:
      • Improve versioning support
      • Improve file upload support
      • Improve domain control
        • AdVideo::create() now use graph-video.facebook.com
      • Improve extensibility
    • Extend logging capabilities to API Request and Response
    • Provide support for AdsAPI v2.2. Changelog
    • Extend test configuration capability
      • Tests that requires features whitelisting are now skippable through config
      • Improve inline documentation with links to docs
    • Bug fixing:
      • getReachEstimate now return an instance of ReachEstimate
      • Fix hashing issue in CustomAudiences::formatParams()
    • Align docs
    Source code(tar.gz)
    Source code(zip)
  • 0.9.11(Oct 8, 2014)

  • 0.9.10(Oct 8, 2014)

  • 0.9.9(Sep 15, 2014)

  • 0.9.8(Sep 12, 2014)

  • 0.9.7(Sep 11, 2014)

    • Add support for AdTag
    • Add support for L2 targeting
    • Implement default normalization for emails in:
      • CustomAudience::addUsers()
      • CustomAudience::removeUsers()
      • CustomAudience::optOutUsers()
    Source code(tar.gz)
    Source code(zip)
  • 0.9.6(Sep 2, 2014)

    • Add archive functionality to AdCampaign, AdSet, AdGroup.
    • Add AdsPixel support:
      • Add AdsPixel class.
      • Add AdsPixelFields enum.
      • Add AdAccount::getAdsPixels() connection method.
    • Update Fields enums + reference for:
      • AdAccount.
      • AdCreative.
    • Add support for Ad scheduling.
    • Upgrade to CustomAudience V2.
      • Implement new payload structure.
        • Update CustomAudienceTypes.
        • Update CustomAudienceFields enum.
      • Deprecate md5 hash algo.
      • Enforce SHA-256 hash algo.
      • CustomAudience::addUsers() and CustomAudience::removeUsers() now return info regarding the requested change.
    • Tests now support/require a user provided page_id for testing targeting.
    Source code(tar.gz)
    Source code(zip)
  • 0.9.5(Jul 10, 2014)

  • 0.9.4(Jun 26, 2014)

    Updating to use the latest version of the PHP SDK

    See README.md for how to instantiate a FacebookSession correctly as you now need to set a default application.

    Improving custom audience handling

    See examples/custom_auciences.php which has a full working example. You now need to pass a CustomAudienceType type the addUsers function and the hashing is handled automatically.

    Source code(tar.gz)
    Source code(zip)
  • 0.9.3(Jun 24, 2014)

Owner
Meta
We are working to build community through open source technology. NB: members must have two-factor auth.
Meta
The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login

Facebook SDK for PHP (v5) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

Meta Archive 3.1k Dec 30, 2022
Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

null 0 Aug 10, 2022
Facebook Query Builder: A query builder for nested requests in the Facebook Graph API

A query builder that makes it easy to create complex & efficient nested requests to Facebook's Graph API to get lots of specific data back with one request.

Sammy Kaye Powers 92 Dec 18, 2022
Zoho CRM API SDK is a wrapper to Zoho CRM APIs. By using this sdk, user can build the application with ease

Archival Notice: This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refe

null 81 Nov 4, 2022
Fully unit tested Facebook SDK v5 integration for Laravel & Lumen

Laravel Facebook SDK A fully unit-tested package for easily integrating the Facebook SDK v5 into Laravel and Lumen 5.0, 5.1, 5.2, & 5.3. This is packa

Sammy Kaye Powers 697 Nov 6, 2022
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

Thuong Le 77 Dec 19, 2022
Laravel wrapper for Facebook's GraphQL

Laravel GraphQL Use Facebook's GraphQL with Laravel 6.0+. It is based on the PHP port of GraphQL reference implementation. You can find more informati

Mikk Mihkel Nurges 1.9k Dec 31, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
SDK of the LINE Login API for PHP

LINE Login for PHP SDK of the LINE Login API for PHP Documentation See the official API documentation for more information. Installation Use the packa

null 4 Sep 15, 2022
Esse SDK em PHP foi desenvolvido no intuito de tornar mais prático a integração com nossa API.

Sobre Beedoo SDK Acessar documentação completa da Beedoo API. A API é organizada seguindo a arquitetura REST, boas práticas, convenções e padrões como

Beedoo Edtech 5 Dec 2, 2021
A PHP SDK for accessing the OpenAI GPT-3 API

OpenAI GPT-3 Api Client in PHP Installation You can install the package via composer: composer require orhanerday/open-ai Usage use Orhanerday\OpenAi\

Orhan erday 462 Jan 2, 2023
PHP SDK for the Sellix Developers API (developers.sellix.io)

PHP SDK for the Sellix Developers API (developers.sellix.io). Quickly get started and create products, payments and more using PHP.

Sellix 7 Nov 23, 2022
ExchangeRatesAPI - Currency Exchange Rates API SDK

ExchangeRatesAPI - Currency Exchange Rates API SDK This is an unofficial wrapper for the awesome, free ExchangeRatesAPI, which provides exchange rate

Ben Major 33 Jun 28, 2022
Mark Sign - Gateway API PHP SDK

Mark Sign - Gateway API PHP SDK

Mark Sign 3 Feb 22, 2022
Light PHP SDK to interact with the Doma(in)Validity API.

Doma(in)Validity PHP SDK. Light PHP SDK to interact with the Doma(in)Validity API. Usage <?php require_once 'vendor/autoload.php'; use Domainvalidit

Doma(In)Validity 2 May 3, 2022
A PHP SDK for the ScreenshotOne.com API to take screenshots of any URL

phpsdk An official Screenshot API client for PHP. It takes minutes to start taking screenshots. Just sign up to get access and secret keys, import the

ScreenshotOne.com 4 Jun 14, 2022
BT Open API SDK in PHP

Mosel, a sdk package for BT open APIs This package is still under construction (july 13th 2022). Open Api are described in the Bouygues Telecom Develo

BboxLab 0 Jul 7, 2022
💛 Modern API development in Laravel. ✍️ Developed by Gentrit Abazi.

Introduction Larapi is a package thats offers you to do modern API development in Laravel with support for new versions of Laravel. Larapi comes inclu

one2tek 93 Oct 28, 2022
Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation Support License Overview Firebase provides the tools and infrastructure y

kreait 1.9k Jan 3, 2023