Google Analytics driven TwitterBot using AppEngine

1,578 views
1,515 views

Published on

An Automated Marketing Solution for my Android app ASOTUnofficial. Presented at Google Developer Group (15 Jan '13)

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,578
On SlideShare
0
From Embeds
0
Number of Embeds
486
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Google Analytics driven TwitterBot using AppEngine

  1. 1. TwitterBot via AppEngine Driven by Google Analytics Nirvana Tikku / @ntikku
  2. 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. 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. 4. How?Service. Two Cron jobs, Twitter, GoogleAnalytics 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. 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. 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. 7. Code1. The authentication process – Google Analytics API – Twitter API2. Seed tweets via Google Analytics3. Publish update to Twitter via Tweepy
  8. 8. Google Analytics Authentication• Google Analytics API – Download key (p12) – Convert to .pem – Add gserviceaccount user to GA profile – Use PyCryptoJWT
  9. 9. Twitter Authentication• Twitter API – Create App – Create OAuth key – Copy params • consumer_key • consumer_secret • access_token • access_token_secret
  10. 10. 2. Seed tweets via trends in GA Query Details
  11. 11. 3. Publishing tweets via Tweepy Merge the context with the template Publish the status update
  12. 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. 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. 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
  15. 15. Thanks

×