Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Twitter APIs for #MediaHackday

1,067 views

Published on

An overview of the Twitter platform and APIs, focussing on the Ads API for the #MediaHackday in Berlin, April 2016

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Twitter APIs for #MediaHackday

  1. 1. Twitter APIs Andy Piper Developer Advocate @andypiper
  2. 2. Twitter APIs deal both with 
 the moment and the past
  3. 3. The Moment: Streaming API t.co/streaming 1% sample, or track keywords The Past: REST API
 t.co/rest Optimize your calls
  4. 4. 4 Create your app: easy
 t.co/apps
 
 Don’t re-invent the wheel: libs t.co/libs
  5. 5. @andypiper
  6. 6. Help? Join the conversation in the Twitter Community forums Follow @TwitterAPI, @AdsAPI and @TwitterDev for platform updates
  7. 7. Developer Resources Documentation dev.twitter.com Streaming API t.co/streaming REST API t.co/rest Create App t.co/apps
 Open Source Libs t.co/libs Code Examples t.co/code
  8. 8. Crashlytics Answers Twitter Digits MoPub
  9. 9. A D S A P I t.co/adsapi
  10. 10. G E T T I N G S TA R T E D
  11. 11. </> PRE-REQUISITES SETUP RUBY VERSION $ ruby -v ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0] $ gem install pry jsonpretty twurl INSTALLING TOOLS & DEPENDENCIES Note: Depending on how your Ruby installation is setup, you may need to run the above “gem install” commands with “sudo”.
  12. 12. AUTHORIZATION More info at: https://dev.twitter.com/oauth OAUTH 1.0A The Ads API uses OAuth 1.0a for authorization and implements the 3-legged OAuth flow.
  13. 13. AUTHORIZATION API key and secret are available under the “Keys and Access Tokens” tab. CONSUMER KEY & SECRET Your consumer key is a publicly visible identifier for your app. You should never share your consumer secret.
  14. 14. </> PRE-REQUISITES SETUP AUTHORIZATION $ twurl authorize --consumer-key key --consumer-secret secret VALIDATE SETUP $ cat ~/.twurlrc TRY IT OUT $ twurl -H ads-api-sandbox.twitter.com "/1/accounts" | jsonpretty
  15. 15. PER MINS / ENDPOINT 25 REQUESTS READS PER MIN / CATEGORY 100 REQUESTS WRITES D E V E LO P E R R AT E L I M I TS More info at: https://dev.twitter.com/ads/basics/rate-limiting
  16. 16. W O R K S H O P
  17. 17. </> INSTALLING THE RUBY SDK $ gem install twitter-ads RUBY SDK SETUP $ twitter-ads twitter-ads v0.3.4 >> START AN INTERACTIVE SESSION Note: Depending on how your Ruby installation is setup, you may need to run the above “gem install” commands with “sudo”.
  18. 18. </> RUBY SDK CLIENT # enable sandbox mode CLIENT.options[:sandbox] = true # load up the account instance account = CLIENT.accounts.first # enable request tracing (optional, = true good for troubleshooting) CLIENT.options[:trace] http://bit.ly/ads-api-client
  19. 19. </>http://bit.ly/ads-api-campaign RUBY SDK CAMPAIGN # create campaign = TwitterAds::Campaign.new(account) your campaign campaign.funding_instrument_id = account.funding_instruments.first.id campaign.daily_budget_amount_local_micro = 1_000_000 campaign.name = 'my first campaign' campaign.paused = true campaign.start_time = Time.now.utc campaign.save
  20. 20. </>http://bit.ly/ads-api-line-item RUBY SDK LINE ITEM # create a line item for the campaign line_item = TwitterAds::LineItem.new(account) line_item.name = 'my first ad' line_item.product_type = TwitterAds::Product::PROMOTED_TWEETS line_item.placements = [TwitterAds::Placement::ALL_ON_TWITTER] line_item.objective = TwitterAds::Objective::TWEET_ENGAGEMENTS line_item.bid_amount_local_micro = 10_000 line_item.paused = true line_item.save line_item.campaign_id = campaign.id
  21. 21. TWEET RETWEET PROMOTED TWEET
  22. 22. </>http://bit.ly/ads-api-promoted-tweet RUBY SDK PROMOTED TWEET # create resource request for a simple null-casted tweet = "/1/accounts/#{account.id}/tweet" tweet_params = { status: ‘Hello @AdsAPI!’ } request = TwitterAds::Request.new(CLIENT, :post, resource, params: tweet_params) tweet = request.perform # promote the tweet using our line item promoted_tweet = TwitterAds::Creative::PromotedTweet.new(account) promoted_tweet.line_item_id = line_item.id promoted_tweet.tweet_id = tweet.body[:data][:id] promoted_tweet.save
  23. 23. </>http://bit.ly/ads-api-targeting RUBY SDK TARGETING # fetching targeting criteria values resource = '/1/targeting_criteria/locations' params = { location_type: 'COUNTRY', q: 'u' } request = TwitterAds::Request.new(CLIENT, :get, resource, params: params) cursor = TwitterAds::Cursor.new(nil, request) # add targeting criteria targeting_criteria = TwitterAds::TargetingCriteria.new(account) targeting_criteria.line_item_id = line_item.id targeting_criteria.targeting_type = 'LOCATION' targeting_criteria.targeting_value = '00a8b25e420adc94' targeting_criteria.save
  24. 24. </>http://bit.ly/ads-api-analytics RUBY SDK ANALYTICS # limit request count and grab the first 10 line items from TwitterAds::Cursor line_items = account.line_items(nil, count: 10)[0..9] # the list of metrics we want to fetch metrics = [:billed_engagements, :billed_follows] # fetching stats on the instance line_items.first.stats(metrics) # fetching stats for multiple line items ids = line_items.map { |line_item| line_item.id } TwitterAds::LineItem.stats(account, ids, metrics)
  25. 25. #THANKYOU

×