0

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:

  1. What is the difference (in Twitter's context) in Oauth 1 and 2?
  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!
  3. 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"
Timo Loescher
  • 119
  • 1
  • 1
  • 16

1 Answers1

0

I can't really answer everything you have asked, but I'll try here:-

  1. In OAuth1 in twitter, access codes were for a lifetime, i.e., would never expire. In OAuth2, there are refresh codes, that are used for new access codes, after previous ones expire. There are many other differences, but this is what really stuck out to me in a Twitter context. You could look at these links to get more details.

How is OAuth 2 different from OAuth 1?

http://hueniverse.com/2010/05/introducing-oauth-2-0/

http://net.tutsplus.com/tutorials/oauth-2-0-the-good-the-bad-the-ugly/

  1. This, I guess, is just Twitter trying to be more secure. I cannot think of any other reason for this.

  2. I don't know about a solution, but maybe as a workaround, you could try and gather users from the followers list of some popular account, like Twitter's official account. You will get a wide range of users to choose from. Just retrieve the list and choose random users from it.

Community
  • 1
  • 1
Apoorv Ashutosh
  • 3,834
  • 7
  • 23
  • 24