{"id":78,"date":"2012-03-13T00:50:12","date_gmt":"2012-03-13T00:50:12","guid":{"rendered":"http:\/\/technicalelvis.com\/blog\/?p=78"},"modified":"2012-03-13T00:50:12","modified_gmt":"2012-03-13T00:50:12","slug":"oauth-with-tweepy","status":"publish","type":"post","link":"https:\/\/technicalelvis.com\/blog\/2012\/03\/13\/oauth-with-tweepy\/","title":{"rendered":"twitter_mining: oauth with tweepy"},"content":{"rendered":"<p>Tweepy provides a module to authenticate with twitter using OAuth. The example below retrieves the auth credentials from a config file and creates a filter stream for the terms 'technical' and 'elvis'. You can get a CONSUMER_KEY and CONSUMER_SECRET by creating a twitter dev account at <a href=\"http:\/\/dev.twitter.com\/apps\/new\">http:\/\/dev.twitter.com\/apps\/new<\/a>. The access token and access token secret can be found under the \"My Applications\" link in your account.<\/p>\n<pre class=\"brush: python; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nimport tweepy\r\nimport ConfigParser\r\nimport os\r\n\r\nclass Listener(tweepy.StreamListener):\r\n    def on_status(self, status):\r\n        print &quot;screen_name='%s' tweet='%s'&quot;%(status.author.screen_name, status.text)\r\n\r\ndef login():\r\n    config = ConfigParser.RawConfigParser()\r\n    fn = os.path.join(os.environ&#x5B;'HOME'],'conf', 'twitter_mining.cfg')\r\n    config.read(fn)\r\n\r\n    CONSUMER_KEY = config.get('auth','CONSUMER_KEY')\r\n    CONSUMER_SECRET = config.get('auth','CONSUMER_SECRET')\r\n    ACCESS_TOKEN = config.get('auth','ACCESS_TOKEN')\r\n    ACCESS_TOKEN_SECRET = config.get('auth','ACCESS_TOKEN_SECRET')\r\n\r\n    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)\r\n    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)\r\n    return auth\r\n\r\ntry:\r\n    auth = login()\r\n    streaming_api = tweepy.streaming.Stream(auth, Listener(), timeout=60)\r\n    streaming_api.filter(follow=None, track=&#x5B;'technical','elvis'])\r\nexcept KeyboardInterrupt:\r\n    print &quot;got keyboardinterrupt&quot;\r\n<\/pre>\n<p>Find the complete codebase on github at: <a title=\"twitter_mining github\" href=\"https:\/\/github.com\/telvis07\/twitter_mining\">https:\/\/github.com\/telvis07\/twitter_mining<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tweepy provides a module to authenticate with twitter using OAuth. The example below retrieves the auth credentials from a config file and creates a filter stream for the terms &#8216;technical&#8217; and &#8216;elvis&#8217;. You can get a CONSUMER_KEY and CONSUMER_SECRET by creating a twitter dev account at http:\/\/dev.twitter.com\/apps\/new. The access token and access token secret can &hellip; <a href=\"https:\/\/technicalelvis.com\/blog\/2012\/03\/13\/oauth-with-tweepy\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">twitter_mining: oauth with tweepy<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[11,12],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-tech","category-twitter_mining"],"_links":{"self":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/comments?post=78"}],"version-history":[{"count":37,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts\/78\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/media?parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/categories?post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/tags?post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}