OAuth and Tokens for dummies


#1

Preface: I have asked this in a few subreddits and on stackoverflow and got upvotes but no answer

I am doing a project for which I need a fairly small number of random Twitter users (about 20 for now) with a near-identical number of followers (within 45000 - 55000 for example). I brushed up on my Python, got Twython set up, and did some test runs and successfully queried the Twitter API for the list of a users followers and such. Then I tried to just randomly search for users. I thought that I would just search for users where (q = " "), loop through them, and stop upon reaching my goal of 20 unique users. However, I came across an error saying “Twitter API returned a 403 (Forbidden), Tour credentials do not allow access to this resource.” When looking around for the issue, it appears that it has to do with the Authentication not having a user-context. Below is my sample code to tell if I am pulling names, but I have a few questions: What is the difference (in Twitter’s context) in Oauth 1 and 2? for someone not looking to develop an app but rather just pull some data, why would I need a user-context? I am not posting anything on anyone’s behalf! How do I go about fixing the issue (or is there a better way of doing this)? Thanks!

from twython import Twython

APP_KEY = 'redacted’
APP_SECRET = ‘redacted’

twitter = Twython(APP_KEY, APP_SECRET, oauth_version=2)
ACCESS_TOKEN = twitter.obtain_access_token()

twitter = Twython(APP_KEY,access_token=ACCESS_TOKEN)

print “hello twitterQuery\n”

search = twitter.search_users(q=’ ')

for user in search[‘ids’]:
print twitter.show_user(user_id=user)[‘screen_name’]

print “\ndone”