I am trying to scrape latitude and longitude of user from Twitter with respect to user names. The user name list is a csv file with more than 50 names in one input file. Th
Assuming that you just want to get the location of the user that is put up in his/her profile page, you can just use the API.get_user from Tweepy. Below is the working code.
#!/usr/bin/env python
from __future__ import print_function
#Import the necessary methods from tweepy library
import tweepy
from tweepy import OAuthHandler
#user credentials to access Twitter API
access_token = "your access token here"
access_token_secret = "your access token secret key here"
consumer_key = "your consumer key here"
consumer_secret = "your consumer secret key here"
def get_user_details(username):
userobj = api.get_user(username)
return userobj
if __name__ == '__main__':
#authenticating the app (https://apps.twitter.com/)
auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#for list of usernames, put them in iterable and call the function
username = 'thinkgeek'
userOBJ = get_user_details(username)
print(userOBJ.location)
Note: This is a crude implementation. Write a proper sleeper function to obey Twitter API access limits.