Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Twitter Streaming API without an application

I am writing a Twitter program for a little market sentiment project I'm doing for fun in Pyhon using the Tweepy library. However, my limited knowledge of API access and whatnot is making most of the Twitter API documentation a bit cryptic. I would like to know a few things, and if this is not the proper place for these questions please let me know so I can post them elsewhere:

1) I do not have an application that I'm writing. Is it still possible to access the Streaming API without one? If so, how to I apply for the consumer and access token keys so I can access the feed with Oauth2?

2) Is it possible to just access my own Twitter feed with all of my followees and then follow a ton of people that I think would have relevant market information?

I currently have a quick program that I found online below, but obviously I am currently getting an "Error: 401" because I do not have consumer key or access token key:

import tweepy
import oauth2

consumer_key = ''
consumer_secret = ''

access_token_key = ''
access_token_secret = ''

auth1 = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth1.set_access_token(access_token_key, access_token_secret)

class StreamListener(tweepy.StreamListener):
    def on_status(self, tweet):
        print 'Ran on_status'

    def on_error(self, status_code):
        print 'Error: ' + str(status_code)
        return False

    def on_data(self, data):
        print 'Ok, this is actually running'

l = StreamListener()
streamer = tweepy.Stream(auth=auth1, listener=l)
setTerms = ['twitter']
streamer.filter(track=setTerms)

Any help is appreciated greatly - thanks.

EDIT: Should I just create a dummy application so I can get access to the API?

like image 247
weskpga Avatar asked May 20 '13 13:05

weskpga


People also ask

Can I use Twitter API without authentication?

You can use the twitter api v1 to take the tweets without using OAuth.


2 Answers

  1. Registering an application on Twitter takes no more than 1 minute. It provides the [consumer/access] [key/secret] which you just need to copy and paste into the code:

    Register a Twitter application.

  2. Basically, all visible data on the Twitter web interface could be fetched with some Twitter API methods, so it seems very doable.

like image 28
chenaren Avatar answered Sep 25 '22 00:09

chenaren


You could just create an application only for yourself to get access to the API: https://dev.twitter.com/apps

1) With tweepy you can also use basic authentication:

This does not work anymore.

auth = tweepy.BasicAuthHandler(username, password)
api = tweepy.API(auth)

2) Yes, you can use the api for querying your feed, and the feed of other users: e.g. API.user_timeline(), API.home_timeline(), API.followers()

Search the tweepy API reference for functions you want to use: http://pythonhosted.org/tweepy/html/api.html

like image 154
michaelkrisper Avatar answered Sep 26 '22 00:09

michaelkrisper