2. Context
• Android App – ASOT Unofficial
– Weekly Trance/Progressive Radio Show
– Track listings, Play YouTube videos
– Google Analytics to track usage
– Parse, AppEngine, YouTube, SoundCloud
– 15 months, 23K active users
– >5K plays a day
• Indie developer, free app
3. Why?
• Automated social marketing
• Unleash GA data
• SEO powered by Twitter
• Link to interesting content as deemed by visitors
• Compelling media content music charts
4. How?
Service. Two Cron jobs, Twitter, Google
Analytics and the AE datastore.
• Seed Tweets – Daily
– Query GA via Core Reporting API
– Store necessary elements in datastore
• Publish Tweets – Hourly
– Tweepy library for auth and publishing
– ‘Update Status’ with Pending Tweets in datastore
5. Technical Details
• AppEngine Python Runtime (2.7)
• Libraries used
– Tweepy
– PyCryptoSignedJWT
– OAuth2Client
– HTTPLib2
– APIClient & URITemplate
• Additional
– Google Account with OAuth credentials
– Twitter API key and OAuth credentials
6. Caveats
• PyCrypto doesn’t play well with PKCS12
certs – need to use PyCryptoSignedJWT
library to sign PEM key
• Trying to dereference names to handles
(i.e. Armin van Buuren -- @arminvanbuuren),
will most likely get your bot banned
7. Code
1. The authentication process
– Google Analytics API
– Twitter API
2. Seed tweets via Google Analytics
3. Publish update to Twitter via Tweepy
8. Google Analytics Authentication
• Google Analytics API
– Download key (p12)
– Convert to .pem
– Add gserviceaccount
user to GA profile
– Use PyCryptoJWT
11. 3. Publishing tweets via Tweepy
Merge the context with the template
Publish the status update
12. @ASOTbot
• 1 month, 70 followers
organically
• Utilizes unicode character
for chart position (1 char)
• Associated with community
hash tag #ASOT for
discoverability
• Attaches YouTube video
youtube.com/watch?v=[videoId]
13. Recap & DIY
• Clone the ga_twitterbot repo on GitHub
• Go to the Google API Console
– Register for Google Analytics
– Create a Service Account
– Setup the client_id, service_account params
– Convert the .p12 key to .pem
• Go to the Twitter API Apps Console
– Create your app
– Setup the tw_consumer_key, tw_consumer_secret,
tw_access_token and tw_access_token_secret params
• Build your GA query via the Google Analytics Query
Explorer and replace SeedTweetsUtil values
• Set your schedule in cron.yaml
14. Useful Links
• Google Analytics Core Reporting API
• Google Service Accounts
• Google Analytics Query Explorer
• Twitter API & Twitter Apps
• Tweepy Library
• PyCryptoJWT
• GitHub project: ga_twitterbot