Ejemplo n.º 1
0
 /**
  * Returns a collection of line items available to the current account.
  *
  * @param string $id
  *
  * @param array $params
  * @return LineItem|Cursor
  */
 public function getLineItems($id = '', $params = [])
 {
     $lineItemsClass = new LineItem();
     return $lineItemsClass->loadResource($this, $id, $params);
 }
Ejemplo n.º 2
0
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: ");
$lineItem->setProductType(Enumerations::PRODUCT_PROMOTED_TWEETS);
$lineItem->setPlacements([Enumerations::PLACEMENT_ALL_ON_TWITTER]);
$lineItem->setObjective(Enumerations::OBJECTIVE_TWEET_ENGAGEMENTS);
$lineItem->setBidAmountLocalMicro(10000);
$lineItem->setPaused(false);
$lineItem->save();
// create request for a simple nullcasted tweet
$media = $twitterAds->upload(['media' => 'kitten.jpg']);
$tweet1 = Tweet::create($account, 'Tweet number 1 ...' . rand() . ' http://twitter.com', ['media_ids' => $media->media_id]);
// promote the tweet using our line item
$promotedTweet = new PromotedTweet($account);
$promotedTweet->setLineItemId($lineItem->getId());
$promotedTweet->setTweetId($tweet1->id);
Ejemplo n.º 3
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);
Ejemplo n.º 4
0
 /**
  * @depends testGetLineItem
  * @param LineItem $lineItem
  * @return Cursor
  */
 public function testGetTargetingCriterias($lineItem)
 {
     /** @var Cursor $cursor */
     $cursor = $lineItem->getTargetingCriteria();
     $this->assertInstanceOf(Cursor::class, $cursor);
     return $cursor;
 }