How Can I Download Facebook Ads Sdk Without Curl UPDATED

How Can I Download Facebook Ads Sdk Without Curl

Facebook Business organisation SDK for PHP

Packagist License Build Status Scrutinizer Scrutinizer Coverage

Introduction

The Facebook Business SDK is a i-stop shop to help our partners better serve their businesses. Partners are using multiple Facebook API'due south to server the needs of their clients. Adopting all these API'south 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 concern SDK bundling many of its APIs into 1 SDK to ease implementation and upkeep. The Business SDK is an upgraded version of the Marketing API SDK that includes the Marketing API too equally many Facebook APIs from different platforms such equally Pages, Business concern Director, Instagram, etc.

Quick Offset

Business SDK Getting Started Guide

Pre-requisites

Register An App

To become started with the SDK, you must accept 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, information technology is recommended that you turn on 'App Secret Proof for Server API calls' in your app's Settings->Avant-garde page.

Obtain An Access Token

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

An admission token is an opaque cord that identifies a User, app, or Page.

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

Refer to our Admission Token Guide to larn more.

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

Installation

The Facebook Business concern SDK requires PHP v.6 or greater.

Composer

The Facebook Business organization 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":                              "five.0.5"                            } }

so install it through composer:

php composer.phar install --no-dev

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

Alternatives

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

Usage

Api main form

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

To instantiate an Api object you volition demand 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 at present available through singleton                              $api              =              Api::case();

In one case 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 gild 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 mode yous would usually do in php:

              use              FacebookAds\Object\AdAccount;                              $account              =              new              AdAccount();                              $account->name              =              'My account name';              echo                              $account->name;

or using the enums:

              utilise              FacebookAds\Object\AdAccount;              utilize              FacebookAds\Object\Fields\AdAccountFields;                              $account              =              new              AdAccount();                              $account->{AdAccountFields::Proper name} =              'My business relationship name';              echo                              $business relationship->{AdAccountFields::Proper name};

Object classes

Facebook Ads entities are defined every bit 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 render all available fields past default. The first argument of the object'due south read method is an array of field names to exist requested.

              utilize              FacebookAds\Object\AdAccount;              use              FacebookAds\Object\Fields\AdAccountFields;                              $fields              =              array(              AdAccountFields::ID,              AdAccountFields::Proper noun, );                              $account              = (new              AdAccount(                $account_id))->getSelf(                $fields);

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

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(),              assortment(              AdSetFields::Name              =>              'My Examination 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              =>              'grand',     ) );              repeat                              $adset->id;

Update Objects

              utilize              FacebookAds\Object\AdSet;              use              FacebookAds\Object\Fields\AdSetFields;                              $ad_set_id              =              '123456';                              $set              =              new              AdSet(                $ad_set_id);                              $fields              =              array( );                              $params              =              assortment(              AdSetFields::Proper name              =>              'My new AdSet proper noun', );                              $ready->updateSelf(                $fields,                              $params);

Delete Objects

              apply              FacebookAds\Object\AdSet;                              $ad_set_id              =              '123456';                              $ready              =              new              AdSet(                $ad_set_id);                              $prepare->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 mostly returned from connectedness methods:

              use              FacebookAds\Object\AdAccount;              employ              FacebookAds\Object\Fields\CampaignFields;                              $business relationship              =              new              AdAccount('<ACT_ID>');                              $cursor              =                              $account->getCampaigns(['id','name']);              // Loop over objects              foreach              (                $cursor              every bit                              $entrada) {              echo                              $campaign->{CampaignFields::NAME}.PHP_EOL; }              // Access objects by index              if              (                $cursor->count() >              0) {              echo              "The start campaign in the cursor is: ".                $cursor[0]->{CampaignFields::NAME}.PHP_EOL; }              // Fetch the adjacent page                              $cursor->fetchAfter();              // New Objects volition exist 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 corporeality 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 cease. Implicit Fetching volition make yous lose control of the number of HTTP asking that will be sent and, for this reason, is disabled by default. Implicit Fetching can exist enabled for a specific cursor:

                              $cursor->setUseImplicitFetch(truthful);

Or globally:

              use              FacebookAds\Cursor;              Cursor::setDefaultUseImplicitFetch(true);

Reverse Iterations

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

              use              FacebookAds\Object\AbstractCrudObject;              /** @var \FacebookAds\Cursor $cursor */                              $cursor->setUseImplicitFetch(truthful);                              $cursor->cease();              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 Advert Business relationship, a Facebook Application and a valid Access Token.

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

Install dependencies

From the root folder run:

php composer.phar install --dev

Execute unit of measurement tests only

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

To run tests individually (be sure non to be pointing to an integration examination 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 examination/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/form/file

Debug

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

This can be identified by amalgam a raw ringlet request and seeing if the response is every bit expected

for example:

              require              __DIR__ .              '/vendor/autoload.php';              utilize              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());                              $business relationship              =              new              AdAccount(                $account_id);                              $account->read(assortment('id'));

When running this lawmaking, this cURL request volition be printed to the console as:

              curl -Thou \   -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 y'all want to acquire more nigh how our SDK lawmaking is generated, delight check this repository.

Issue

Since nosotros want to handle bugs more efficiently, we've decided to close event reporting in Github and move to our defended bug reporting channel. If you lot encounter a bug with Business SDK (PHP), please study the outcome at our programmer bug reporting channel.

DOWNLOAD HERE

Posted by: nawrockiusionswut1967.blogspot.com

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel