Code for retrieving followers from Twitter API results in al

This is the place for queries that don't fit in any of the other categories.

Code for retrieving followers from Twitter API results in al

Postby Clockchan » Wed Aug 07, 2013 9:05 pm

I would like to scrape the Twitter API to retrieve the follower ids for specific users, so that I can map their connections.

When I run the code below, the followerIds for each individual user are the same, which can't be right. Every time I run the program I get a different common follower id...every user has the same follower id, but the follower id that's repeated is different every time I run the program. How do I fix this problem?

Code: Select all
        import json
    except ImportError:
        import simplejson as json
        import urllib2
        import urllib
        import codecs
        import time
        import datetime
        import os
        import random
        import time
        import tweepy
    from tweepy.parsers import RawParser
        import sys

    fhLog ="LOG.txt",'a','UTF-8')
    def logPrint(s):
    print s

    #List of screennames of users whose followers we want to get
    users =["_AReichert",

     # == OAuth Authentication ==

    # The consumer keys can be found on your application's Details
    # page located at (under "OAuth settings")

    # After the step above, you will be redirected to your app's page.
    # Create an access token under the the "Your access token" section

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    rawParser = RawParser()
    api = tweepy.API(auth_handler=auth, parser=rawParser)

    #Will store ids of followers for each user in the user_output directory
    os.system("mkdir -p user_output") #Create directory if it does not exist

    for user in users:
         print("Getting user %s of %s"%(userCnt,len(users)))
        nCursor=-1#First page
        while count>0:

               fh=open("user_output/"+str(id_str)+"_" + str(count) + ".json","r")
               fh=open("user_output/"+str(id_str)+"_" + str(count) + ".json","w")

            if nCursor=="0":
                print("Another page to get")


    logPrint("\nDONE! Completed Successfully")
Posts: 1
Joined: Wed Aug 07, 2013 8:51 pm

Re: Code for retrieving followers from Twitter API results i

Postby micseydel » Wed Aug 07, 2013 11:09 pm

Can you replicate your problem with 10 or less lines of code that we are able to run ourselves?
Join the #python-forum IRC channel on for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from :)
User avatar
Posts: 2253
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 8 guests