Exemplo n.º 1
0
 /**
  * @depends testGetAccounts
  * @param Cursor $accounts
  * @return Account
  */
 public function testGetAccount($accounts)
 {
     /** @var Account $firstAccount */
     $firstAccount = $accounts->next();
     $account = $this->twitter->getAccounts($firstAccount->getId());
     $this->assertEquals($firstAccount->getId(), $account->getId());
     return $account;
 }
 public function testTailoredAudienceChangesCanBeFetchedAndUpdated()
 {
     $this->markTestSkipped('waiting for write access to twitter ads api');
     $accounts = $this->twitter->getAccounts();
     $this->assertGreaterThan(0, count($accounts));
     $account = iterator_to_array($accounts)[0];
     $audience = new TailoredAudience($account);
     $audience->setListType(TailoredAudience::LIST_TYPE_EMAIL);
     $audience->save();
 }
Exemplo n.º 3
0
<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Account;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Campaign;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\LineItem;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Tweet;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\PromotedTweet;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\Video;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\WebsiteCard;
use Hborras\TwitterAdsSDK\TwitterAds\Enumerations;
require '../autoload.php';
const CONSUMER_KEY = 'your consumer key';
const CONSUMER_SECRET = 'your consumer secret';
const ACCESS_TOKEN = 'your access token';
const ACCESS_TOKEN_SECRET = 'your access token secret';
const ACCOUNT_ID = 'account id';
// Create twitter ads client
$twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// load up the account instance, campaign and line item
/** @var Account $account */
$account = $twitterAds->getAccounts(ACCOUNT_ID);
/** Upload media */
$media = $twitterAds->upload(['media' => 'video.mp4', 'media_type' => 'video/mp4'], true);
/** Create a video entity and save it*/
$video = new Video($account);
$video->setTitle("Test Video " . rand());
$video->setDescription("Description" . rand());
$video->setVideoMediaId($media->media_id);
$video->save();
 /**
  * Set up the client
  */
 protected function setUp()
 {
     $this->twitter = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET, false);
     $this->account = $this->twitter->getAccounts()->next();
 }
Exemplo n.º 5
0
<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Analytics;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\LineItem;
require '../autoload.php';
const CONSUMER_KEY = 'your consumer key';
const CONSUMER_SECRET = 'your consumer secret';
const ACCESS_TOKEN = 'your access token';
const ACCESS_TOKEN_SECRET = 'your access token secret';
const ACCOUNT_ID = 'account id';
// Create twitter ads client
$twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// load up the account instance, campaign and line item
$account = $twitterAds->getAccounts(ACCOUNT_ID);
// Limit request count and grab the first 10 line items from Cursor
$lineItems = $account->getLineItems("", ['count' => 10]);
// The list of metrics we want to fetch, for a full list of possible metrics
$metrics = [Analytics::ANALYTICS_METRIC_GROUPS_ENGAGEMENT, Analytics::ANALYTICS_METRIC_GROUPS_BILLING];
// Fetching stats on the instance
/** @var LineItem $lineItem */
$lineItem = $lineItems->first();
$stats = $lineItem->stats($metrics);
// Fetching stats for multiple line items
$ids = array_map(function ($o) {
    return $o->getId();
}, $lineItems->getCollection());
$stats = LineItem::all_stats($account, $ids, $metrics);
<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Account;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Campaign;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\LineItem;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Tweet;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\PromotedTweet;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\WebsiteCard;
use Hborras\TwitterAdsSDK\TwitterAds\Enumerations;
require '../autoload.php';
const CONSUMER_KEY = 'your consumer key';
const CONSUMER_SECRET = 'your consumer secret';
const ACCESS_TOKEN = 'your access token';
const ACCESS_TOKEN_SECRET = 'your access token secret';
const ACCOUNT_ID = 'account id';
// Create twitter ads client
$twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// load up the account instance, campaign and line item
/** @var Account $account */
$account = $twitterAds->getAccounts(ACCOUNT_ID);
// create request for a simple nullcasted tweet
$media = $twitterAds->upload(['media' => 'twitter-gif.gif', 'media_type' => 'image/gif'], true);
$tweet = Tweet::create($account, 'Tweet with chunked upload GIF...' . rand() . ' http://twitter.com', ['media_ids' => $media->media_id]);
 private function getAccount()
 {
     $accounts = $this->twitter->getAccounts();
     $this->assertGreaterThan(0, count($accounts));
     return iterator_to_array($accounts)[0];
 }
use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\Account;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Campaign;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\LineItem;
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Tweet;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\PromotedTweet;
use Hborras\TwitterAdsSDK\TwitterAds\Creative\WebsiteCard;
use Hborras\TwitterAdsSDK\TwitterAds\Enumerations;
require '../autoload.php';
const CONSUMER_KEY = 'your consumer key';
const CONSUMER_SECRET = 'your consumer secret';
const ACCESS_TOKEN = 'your access token';
const ACCESS_TOKEN_SECRET = 'your access token secret';
const ACCOUNT_ID = 'account id';
// Create twitter ads client
$twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// load up the account instance, campaign and line item
/** @var Account $account */
$account = $twitterAds->getAccounts(ACCOUNT_ID);
/** @var Campaign $campaign */
$campaign = new Campaign($account);
$campaign->setFundingInstrumentId($account->getFundingInstruments()->first()->getId());
$campaign->setDailyBudgetAmountLocalMicro(1000000);
$campaign->setName("My first campaign: ");
$campaign->setPaused(false);
$campaign->setStartTime(new \DateTime());
$campaign->save();
// Create a line item for the campaign
$lineItem = new LineItem($account);
$lineItem->setCampaignId($campaign->getId());
$lineItem->setName("My first line item: ");
<?php

use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\TailoredAudience;
require '../autoload.php';
const CONSUMER_KEY = 'your consumer key';
const CONSUMER_SECRET = 'your consumer secret';
const ACCESS_TOKEN = 'your access token';
const ACCESS_TOKEN_SECRET = 'your access token secret';
const ACCOUNT_ID = 'account id';
/** Create twitter ads client */
$twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
/** If the file is too large, I highly recommend increase the timeout */
$twitterAds->setTimeouts(5, 45);
// Retrieve account information
$account = $twitterAds->getAccounts(ACCOUNT_ID);
/** If the file is not hashed line by line, you need to hash it, for example for emails is this code*/
$file = fopen("path/to/list.txt", "r");
$newFile = fopen('path/to/new_list.txt', 'w');
while (!feof($file)) {
    $line = fgets($file);
    $normalized_email = strtolower(trim($line, " \t\r\n\v."));
    $normalized_email = hash('sha256', $normalized_email);
    fwrite($newFile, $normalized_email . "\n");
    # do same stuff with the $line
}
fclose($newFile);
fclose($file);
$audience = new TailoredAudience($account);
$audience->create('path/to/new_list.txt', 'Test List', TailoredAudience::LIST_TYPE_EMAIL);
/** @var TwitterAds\TailoredAudience\TailoredAudienceChanges $status */
Exemplo n.º 10
0
 public function testUrl()
 {
     $url = $this->twitter->url('oauth/authorize', array('foo' => 'bar', 'baz' => 'qux'));
     $this->assertEquals('https://api.twitter.com/oauth/authorize?foo=bar&baz=qux', $url);
 }