Google Analytics driven TwitterBot using AppEngine
-
Upload
nirvana-tikku -
Category
Technology
-
view
1.251 -
download
3
description
Transcript of Google Analytics driven TwitterBot using AppEngine
TwitterBot via AppEngineDriven by Google Analytics
Nirvana Tikku / @ntikku
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
Why?
• Automated social marketing• Unleash GA data• SEO powered by Twitter• Link to interesting content as deemed by
visitors
• Compelling media content music charts
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
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
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
Code
1. The authentication process– Google Analytics API– Twitter API
2. Seed tweets via Google Analytics3. Publish update to Twitter via Tweepy
Google Analytics Authentication
• Google Analytics API– Download key (p12)– Convert to .pem– Add gserviceaccount
user to GA profile– Use PyCryptoJWT
Twitter Authentication• Twitter API– Create App– Create OAuth key– Copy params
• consumer_key• consumer_secret• access_token• access_token_secret
2. Seed tweets via trends in GA
Query Details
3. Publishing tweets via Tweepy
Merge the context with the template
Publish the status update
@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]
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
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
Thanks