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?
You can use the twitter api v1 to take the tweets without using OAuth.
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.
Basically, all visible data on the Twitter web interface could be fetched with some Twitter API methods, so it seems very doable.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With