PHP code example of pmg / twitterads

1. Go to this page and download the library: Download pmg/twitterads library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pmg / twitterads example snippets


$twitter = new \PMG\TwitterAds\TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, TOKEN_SECRET);
//We will assume for the rest of the examples that $twitter is defined.

use PMG\TwitterAds\TailoredAudiences\TailoredAudienceRequest;

$request = new TailoredAudienceRequest('accounts/:account_id/tailored_audiences', ['account_id' => ACCOUNT]);
$response = $twitter->send($request);

//Returns PMG\TwitterAds\Response

object(PMG\TwitterAds\Response)#228 (3) {
  ["code":"PMG\TwitterAds\Response":private]=>
  int(200)
  ["headers":"PMG\TwitterAds\Response":private]=>
  array(8) {
    ["content-length"]=>
    string(4) "3749"
    ["content-type"]=>
    string(30) "application/json;charset=utf-8"
    ["date"]=>
    string(29) "Tue, 19 Jul 2016 14:55:21 GMT"
    ["expires"]=>
    string(29) "Tue, 31 Mar 1981 05:00:00 GMT"
    ["status"]=>
    string(6) "200 OK"
    ["x-rate-limit-limit"]=>
    string(2) "15"
    ["x-rate-limit-remaining"]=>
    string(2) "13"
    ["x-rate-limit-reset"]=>
    string(10) "1468940943"
  }
  ["body":"PMG\TwitterAds\Response":private]=>
  array(2) {
    ["id"]=>
    int(2222)
    ["id_str"]=>
    string(9) "2222"
  }
}

$file = new \SplFileObject('somefile.txt');
$tonFile = new TonUpload($twitter, $file, 'text/plain');

$response = $tonFile->upload();

//Returns PMG\TwitterAds\Response