SlideShare a Scribd company logo
1 of 26
Download to read offline
Twitter APIs
Andy Piper
Developer Advocate
@andypiper
Twitter APIs deal both with 

the moment and the past
The Moment: Streaming API
t.co/streaming
1% sample, or track keywords
The Past: REST API

t.co/rest
Optimize your calls
4
Create your app: easy

t.co/apps



Don’t re-invent the wheel: libs
t.co/libs
@andypiper
Help?
Join the conversation in the
Twitter Community forums
Follow @TwitterAPI, @AdsAPI and
@TwitterDev for platform updates
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
Crashlytics Answers Twitter Digits MoPub
A D S A P I
t.co/adsapi
G E T T I N G S TA R T E D
</>
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”.
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.
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.
</>
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
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
W O R K S H O P
</>
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”.
</>
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
</>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
</>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
TWEET RETWEET PROMOTED TWEET
</>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
</>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
</>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)
#THANKYOU

More Related Content

What's hot

How to hack a node app? @ GDG DevFest Ukraine 2017
How to hack a node app? @  GDG DevFest Ukraine 2017How to hack a node app? @  GDG DevFest Ukraine 2017
How to hack a node app? @ GDG DevFest Ukraine 2017Asim Hussain
 
Apps for Science - Elsevier Developer Network Workshop 201102
Apps for Science - Elsevier Developer Network Workshop 201102Apps for Science - Elsevier Developer Network Workshop 201102
Apps for Science - Elsevier Developer Network Workshop 201102remko caprio
 
Really Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know AboutReally Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know AboutAngela Bowman
 
Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)Raffi Krikorian
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress SecurityShawn Hooper
 
Intro to developing for @twitterapi
Intro to developing for @twitterapiIntro to developing for @twitterapi
Intro to developing for @twitterapiRaffi Krikorian
 
WordPress Security Presentation
WordPress Security PresentationWordPress Security Presentation
WordPress Security PresentationAndrew Paton
 
Hunting for the secrets in a cloud forest
Hunting for the secrets in a cloud forestHunting for the secrets in a cloud forest
Hunting for the secrets in a cloud forestSecuRing
 
All your family secrets belong to us—Worrisome security issues in tracker apps
All your family secrets belong to us—Worrisome security issues in tracker appsAll your family secrets belong to us—Worrisome security issues in tracker apps
All your family secrets belong to us—Worrisome security issues in tracker appsPriyanka Aash
 
Attacking open source using abandoned resources
Attacking open source using abandoned resourcesAttacking open source using abandoned resources
Attacking open source using abandoned resourcesAdam Baldwin
 
Approaching the unknown - Windows Phone application security assessment guide
Approaching the unknown - Windows Phone application security assessment guideApproaching the unknown - Windows Phone application security assessment guide
Approaching the unknown - Windows Phone application security assessment guideSecuRing
 
Mobile Performance Testing Crash Course
Mobile Performance Testing Crash CourseMobile Performance Testing Crash Course
Mobile Performance Testing Crash CourseTechWell
 
What should I do when my website got hack?
What should I do when my website got hack?What should I do when my website got hack?
What should I do when my website got hack?Sumedt Jitpukdebodin
 
Testing iOS apps without jailbreak in 2018
Testing iOS apps without jailbreak in 2018Testing iOS apps without jailbreak in 2018
Testing iOS apps without jailbreak in 2018SecuRing
 
Poisoning Google images
Poisoning Google imagesPoisoning Google images
Poisoning Google imageslukash4
 
Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014Paris Android User Group
 

What's hot (20)

How to hack a node app? @ GDG DevFest Ukraine 2017
How to hack a node app? @  GDG DevFest Ukraine 2017How to hack a node app? @  GDG DevFest Ukraine 2017
How to hack a node app? @ GDG DevFest Ukraine 2017
 
Apps for Science - Elsevier Developer Network Workshop 201102
Apps for Science - Elsevier Developer Network Workshop 201102Apps for Science - Elsevier Developer Network Workshop 201102
Apps for Science - Elsevier Developer Network Workshop 201102
 
Really Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know AboutReally Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know About
 
What's happening here?
What's happening here?What's happening here?
What's happening here?
 
Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)
 
Introduction to WordPress Security
Introduction to WordPress SecurityIntroduction to WordPress Security
Introduction to WordPress Security
 
Intro to developing for @twitterapi
Intro to developing for @twitterapiIntro to developing for @twitterapi
Intro to developing for @twitterapi
 
WordPress Security Presentation
WordPress Security PresentationWordPress Security Presentation
WordPress Security Presentation
 
API Design - 3rd Edition
API Design - 3rd EditionAPI Design - 3rd Edition
API Design - 3rd Edition
 
TL; DR: iOS 9R
TL; DR: iOS 9RTL; DR: iOS 9R
TL; DR: iOS 9R
 
Hunting for the secrets in a cloud forest
Hunting for the secrets in a cloud forestHunting for the secrets in a cloud forest
Hunting for the secrets in a cloud forest
 
All your family secrets belong to us—Worrisome security issues in tracker apps
All your family secrets belong to us—Worrisome security issues in tracker appsAll your family secrets belong to us—Worrisome security issues in tracker apps
All your family secrets belong to us—Worrisome security issues in tracker apps
 
Attacking open source using abandoned resources
Attacking open source using abandoned resourcesAttacking open source using abandoned resources
Attacking open source using abandoned resources
 
Invoke-DOSfuscation
Invoke-DOSfuscationInvoke-DOSfuscation
Invoke-DOSfuscation
 
Approaching the unknown - Windows Phone application security assessment guide
Approaching the unknown - Windows Phone application security assessment guideApproaching the unknown - Windows Phone application security assessment guide
Approaching the unknown - Windows Phone application security assessment guide
 
Mobile Performance Testing Crash Course
Mobile Performance Testing Crash CourseMobile Performance Testing Crash Course
Mobile Performance Testing Crash Course
 
What should I do when my website got hack?
What should I do when my website got hack?What should I do when my website got hack?
What should I do when my website got hack?
 
Testing iOS apps without jailbreak in 2018
Testing iOS apps without jailbreak in 2018Testing iOS apps without jailbreak in 2018
Testing iOS apps without jailbreak in 2018
 
Poisoning Google images
Poisoning Google imagesPoisoning Google images
Poisoning Google images
 
Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014Workshop: building your mobile backend with Parse - Droidcon Paris2014
Workshop: building your mobile backend with Parse - Droidcon Paris2014
 

Similar to Twitter APIs for #MediaHackday

API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsTom Johnson
 
Creating a mule project with raml and api
Creating a mule project with raml and apiCreating a mule project with raml and api
Creating a mule project with raml and apiBhargav Ranjit
 
Deploy a web API in 15'
Deploy a web API in 15'Deploy a web API in 15'
Deploy a web API in 15'Restlet
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
Build Android App using GCE & GAE
Build Android App using GCE & GAEBuild Android App using GCE & GAE
Build Android App using GCE & GAELove Sharma
 
How to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdfHow to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdfKaty Slemon
 
I Love APIs - Oct 2015
I Love APIs - Oct 2015I Love APIs - Oct 2015
I Love APIs - Oct 2015Mike McNeil
 
How to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdfHow to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdfKaty Slemon
 
Creating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APICreating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APIDavid Keener
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaPantheon
 
API Management Workshop (at Startupbootcamp Berlin)
API Management Workshop (at Startupbootcamp Berlin)API Management Workshop (at Startupbootcamp Berlin)
API Management Workshop (at Startupbootcamp Berlin)3scale
 
Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngineikailan
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsMarcelo Pinheiro
 
Play Your API with MuleSoft API Notebook
Play Your API with MuleSoft API NotebookPlay Your API with MuleSoft API Notebook
Play Your API with MuleSoft API NotebookRakesh Kumar Jha
 

Similar to Twitter APIs for #MediaHackday (20)

API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
Creating a mule project with raml and api
Creating a mule project with raml and apiCreating a mule project with raml and api
Creating a mule project with raml and api
 
Deploy a web API in 15'
Deploy a web API in 15'Deploy a web API in 15'
Deploy a web API in 15'
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Build Android App using GCE & GAE
Build Android App using GCE & GAEBuild Android App using GCE & GAE
Build Android App using GCE & GAE
 
How to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdfHow to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdf
 
I Love APIs - Oct 2015
I Love APIs - Oct 2015I Love APIs - Oct 2015
I Love APIs - Oct 2015
 
How to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdfHow to Integrate Google Adwords API in Laravel App.pdf
How to Integrate Google Adwords API in Laravel App.pdf
 
Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
Creating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APICreating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services API
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon Vienna
 
API Management Workshop (at Startupbootcamp Berlin)
API Management Workshop (at Startupbootcamp Berlin)API Management Workshop (at Startupbootcamp Berlin)
API Management Workshop (at Startupbootcamp Berlin)
 
Api manager preconference
Api manager preconferenceApi manager preconference
Api manager preconference
 
Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
Play Your API with MuleSoft API Notebook
Play Your API with MuleSoft API NotebookPlay Your API with MuleSoft API Notebook
Play Your API with MuleSoft API Notebook
 
AIR & API
AIR & APIAIR & API
AIR & API
 

More from Andy Piper

Adapt & Survive
Adapt & SurviveAdapt & Survive
Adapt & SurviveAndy Piper
 
Rebooting A Community #DevRelCon
Rebooting A Community #DevRelConRebooting A Community #DevRelCon
Rebooting A Community #DevRelConAndy Piper
 
Imagining the Future, when the Future is already Now
Imagining the Future, when the Future is already NowImagining the Future, when the Future is already Now
Imagining the Future, when the Future is already NowAndy Piper
 
Developer Advocacy - A Life Less Ordinary
Developer Advocacy - A Life Less OrdinaryDeveloper Advocacy - A Life Less Ordinary
Developer Advocacy - A Life Less OrdinaryAndy Piper
 
Twitter in the Internet of Things
Twitter in the Internet of ThingsTwitter in the Internet of Things
Twitter in the Internet of ThingsAndy Piper
 
Twitter APIs - the starter guide
Twitter APIs - the starter guideTwitter APIs - the starter guide
Twitter APIs - the starter guideAndy Piper
 
Connecting to the pulse of the planet with Twitter APIs
Connecting to the pulse of the planet with Twitter APIsConnecting to the pulse of the planet with Twitter APIs
Connecting to the pulse of the planet with Twitter APIsAndy Piper
 
Internet ALL the Things - a walking tour of MQTT
Internet ALL the Things - a walking tour of MQTTInternet ALL the Things - a walking tour of MQTT
Internet ALL the Things - a walking tour of MQTTAndy Piper
 
Combining Context with Signals in the IoT (longer version)
Combining Context with Signals in the IoT (longer version)Combining Context with Signals in the IoT (longer version)
Combining Context with Signals in the IoT (longer version)Andy Piper
 
Why the Internet of Things will be built on Open Source
Why the Internet of Things will be built on Open SourceWhy the Internet of Things will be built on Open Source
Why the Internet of Things will be built on Open SourceAndy Piper
 
Combining Context with Signals in the Internet of Things
Combining Context with Signals in the Internet of ThingsCombining Context with Signals in the Internet of Things
Combining Context with Signals in the Internet of ThingsAndy Piper
 
MQTT - standards-based plumbing for the Internet of Things
MQTT - standards-based plumbing for the Internet of ThingsMQTT - standards-based plumbing for the Internet of Things
MQTT - standards-based plumbing for the Internet of ThingsAndy Piper
 
My Quantified Self and the promise of wearables
My Quantified Self and the promise of wearablesMy Quantified Self and the promise of wearables
My Quantified Self and the promise of wearablesAndy Piper
 
Why Data, Code and Mobile converge in the Open Cloud
Why Data, Code and Mobile converge in the Open CloudWhy Data, Code and Mobile converge in the Open Cloud
Why Data, Code and Mobile converge in the Open CloudAndy Piper
 
From Cloud Computing to Platform as a Service – BCS Oxfordshire
From Cloud Computing to Platform as a Service – BCS OxfordshireFrom Cloud Computing to Platform as a Service – BCS Oxfordshire
From Cloud Computing to Platform as a Service – BCS OxfordshireAndy Piper
 
Why Apps, Data and Mobile Converge in the Open Cloud
Why Apps, Data and Mobile Converge in the Open CloudWhy Apps, Data and Mobile Converge in the Open Cloud
Why Apps, Data and Mobile Converge in the Open CloudAndy Piper
 
The Internet of Things is Made of Signals
The Internet of Things is Made of SignalsThe Internet of Things is Made of Signals
The Internet of Things is Made of SignalsAndy Piper
 
How to Write a Web App in fewer than 140 Characters
How to Write a Web App in fewer than 140 CharactersHow to Write a Web App in fewer than 140 Characters
How to Write a Web App in fewer than 140 CharactersAndy Piper
 
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of ThingsMQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of ThingsAndy Piper
 
Run your Java apps on Cloud Foundry
Run your Java apps on Cloud FoundryRun your Java apps on Cloud Foundry
Run your Java apps on Cloud FoundryAndy Piper
 

More from Andy Piper (20)

Adapt & Survive
Adapt & SurviveAdapt & Survive
Adapt & Survive
 
Rebooting A Community #DevRelCon
Rebooting A Community #DevRelConRebooting A Community #DevRelCon
Rebooting A Community #DevRelCon
 
Imagining the Future, when the Future is already Now
Imagining the Future, when the Future is already NowImagining the Future, when the Future is already Now
Imagining the Future, when the Future is already Now
 
Developer Advocacy - A Life Less Ordinary
Developer Advocacy - A Life Less OrdinaryDeveloper Advocacy - A Life Less Ordinary
Developer Advocacy - A Life Less Ordinary
 
Twitter in the Internet of Things
Twitter in the Internet of ThingsTwitter in the Internet of Things
Twitter in the Internet of Things
 
Twitter APIs - the starter guide
Twitter APIs - the starter guideTwitter APIs - the starter guide
Twitter APIs - the starter guide
 
Connecting to the pulse of the planet with Twitter APIs
Connecting to the pulse of the planet with Twitter APIsConnecting to the pulse of the planet with Twitter APIs
Connecting to the pulse of the planet with Twitter APIs
 
Internet ALL the Things - a walking tour of MQTT
Internet ALL the Things - a walking tour of MQTTInternet ALL the Things - a walking tour of MQTT
Internet ALL the Things - a walking tour of MQTT
 
Combining Context with Signals in the IoT (longer version)
Combining Context with Signals in the IoT (longer version)Combining Context with Signals in the IoT (longer version)
Combining Context with Signals in the IoT (longer version)
 
Why the Internet of Things will be built on Open Source
Why the Internet of Things will be built on Open SourceWhy the Internet of Things will be built on Open Source
Why the Internet of Things will be built on Open Source
 
Combining Context with Signals in the Internet of Things
Combining Context with Signals in the Internet of ThingsCombining Context with Signals in the Internet of Things
Combining Context with Signals in the Internet of Things
 
MQTT - standards-based plumbing for the Internet of Things
MQTT - standards-based plumbing for the Internet of ThingsMQTT - standards-based plumbing for the Internet of Things
MQTT - standards-based plumbing for the Internet of Things
 
My Quantified Self and the promise of wearables
My Quantified Self and the promise of wearablesMy Quantified Self and the promise of wearables
My Quantified Self and the promise of wearables
 
Why Data, Code and Mobile converge in the Open Cloud
Why Data, Code and Mobile converge in the Open CloudWhy Data, Code and Mobile converge in the Open Cloud
Why Data, Code and Mobile converge in the Open Cloud
 
From Cloud Computing to Platform as a Service – BCS Oxfordshire
From Cloud Computing to Platform as a Service – BCS OxfordshireFrom Cloud Computing to Platform as a Service – BCS Oxfordshire
From Cloud Computing to Platform as a Service – BCS Oxfordshire
 
Why Apps, Data and Mobile Converge in the Open Cloud
Why Apps, Data and Mobile Converge in the Open CloudWhy Apps, Data and Mobile Converge in the Open Cloud
Why Apps, Data and Mobile Converge in the Open Cloud
 
The Internet of Things is Made of Signals
The Internet of Things is Made of SignalsThe Internet of Things is Made of Signals
The Internet of Things is Made of Signals
 
How to Write a Web App in fewer than 140 Characters
How to Write a Web App in fewer than 140 CharactersHow to Write a Web App in fewer than 140 Characters
How to Write a Web App in fewer than 140 Characters
 
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of ThingsMQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
 
Run your Java apps on Cloud Foundry
Run your Java apps on Cloud FoundryRun your Java apps on Cloud Foundry
Run your Java apps on Cloud Foundry
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Twitter APIs for #MediaHackday

  • 1. Twitter APIs Andy Piper Developer Advocate @andypiper
  • 2. Twitter APIs deal both with 
 the moment and the past
  • 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 Create your app: easy
 t.co/apps
 
 Don’t re-invent the wheel: libs t.co/libs
  • 6. Help? Join the conversation in the Twitter Community forums Follow @TwitterAPI, @AdsAPI and @TwitterDev for platform updates
  • 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.
  • 10. A D S A P I t.co/adsapi
  • 11. G E T T I N G S TA R T E D
  • 12. </> 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”.
  • 13. 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.
  • 14. 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.
  • 15. </> 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
  • 16. 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
  • 17. W O R K S H O P
  • 18. </> 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”.
  • 19. </> 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
  • 20. </>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
  • 21. </>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
  • 23. </>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
  • 24. </>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
  • 25. </>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)