Python – 在 Tweepy 中放置对象
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。
地方
Tweepy 模块中的Place
对象包含有关地点的信息。
以下是 Place 对象中的属性列表:
- id : The ID of the place.
- url : The URL representing the location of the place.
- place_type : The type of location represented by the place.
- name : The name of the place.
- full_name : The full name of the place.
- country_code : The code of the country of the place.
- country : The name of the country of the place.
- contained_within : A Place object containing the place.
- geometry : The geometry of the place.
- polylines : The polylines of the place.
- centroid : The centroid of the place.
- bounding_box : The coordinates which encloses the place.
示例:使用geo_id()
方法获取地点。考虑伦敦市。
# import the module
import tweepy
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# set access to user's access key and access secret
auth.set_access_token(access_token, access_token_secret)
# calling the api
api = tweepy.API(auth)
# Twitter ID of London
id = "457b4814b4240d87"
# fetching the location
place = api.geo_id(id)
# printing the information
print("The id is : " + place.id)
print("The url is : " + place.url)
print("The place_type is : " + place.place_type)
print("The name is : " + place.name)
print("The full_name is : " + place.full_name)
print("The country_code is : " + place.country_code)
print("The country is : " + place.country)
print("The contained_within is : " + str(place.contained_within))
print("The geometry is : " + str(place.geometry))
print("The polylines are : " + str(place.polylines))
print("The centroid is : " + str(place.centroid))
print("The bounding_box is : " + str(place.bounding_box))
输出 :
The id is : 457b4814b4240d87
The url is : https://api.twitter.com/1.1/geo/id/457b4814b4240d87.json
The place_type is : city
The name is : London
The full_name is : London, England
The country_code is : GB
The country is : United Kingdom
The contained_within is : [Place(_api=, id=’1090d3ced4b75d04′, url=’https://api.twitter.com/1.1/geo/id/1090d3ced4b75d04.json’, place_type=’admin’, name=’London’, full_name=’London’, country_code=’GB’, country=’United Kingdom’, centroid=[0.07110233274688144, 51.5989395], bounding_box=BoundingBox(_api=, type=’Polygon’, coordinates=[[[-0.853907, 51.105205], [-0.853907, 52.092674], [0.958128, 52.092674], [0.958128, 51.105205], [-0.853907, 51.105205]]]), attributes={})]
The geometry is : None
The polylines are : []
The centroid is : [-0.14032122753075282, 51.50009175]
The bounding_box is : BoundingBox(_api=, type=’Polygon’, coordinates=[[[-0.187894, 51.483718], [-0.187894, 51.5164655], [-0.109978, 51.5164655], [-0.109978, 51.483718], [-0.187894, 51.483718]]])
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。