Python – API.geo_id() in Tweepy
Last Updated :
11 Jun, 2020
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.geo_id()
The geo_id()
method of the API
class in Tweepy module is used to fetch a location by its Twitter ID.
Syntax : API.geo_id(id)
Parameters :
- id : Twitter ID of the location.
Returns : a list of objects of class Place
Example 1 :
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
id = "457b4814b4240d87"
location = api.geo_id( id )
print ( "Place Type : " + location.place_type)
print ( "Name : " + location.name)
print ( "Full Name : " + location.full_name)
print ( "Country : " + location.country)
|
Output :
Place Type : city
Name : London
Full Name : London, England
Country : United Kingdom
Example 2 : Exception is raised when giving invalid ID.
id = "xyz"
location = api.geo_id( id )
|
Output :
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'message': 'Sorry, that page does not exist', 'code': 34}]
Share your thoughts in the comments
Please Login to comment...