如何使用 Tweepy 和 Python 发送坐标到 Twitter 状态更新

How to send co-ordinates with Tweepy and Python to Twitter status update

我想使用 Python 2.7 和 Tweepy 向 Twitter 发送带有消息和一些地理坐标的状态更新。我经常使用 Tweepy,其他一切正常,但是当我尝试传递坐标时,我收到一条 'Invalid coordinates.' 消息...坐标本身是来自 Bing 的 [=26] 的整数=].

在这里查看 tweepy 请求:http://docs.tweepy.org/en/v3.5.0/api.html

我正在做的代码:

latitude = 51.5118029
longitude = -0.1337666
tweet = "Some tweet!"
api.update_status(tweet, latitude, longitude)

我得到:

raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{u'message': u'Invalid coordinates.', u'code': 3}]

非常感谢任何帮助!

事实证明(不出所料)您需要声明 lat/lng 是什么,即

api.update_status(tweet, lat = latitude, long = longitude)

试试这个:

api.update_status(tweet, lat=latitude, long=longitude)

没有 latlong 参数名称,tweepy 认为您提供的是 in_reply_to_status_id。这是实际的方法声明:

API.update_status(status[, in_reply_to_status_id][, lat][, long][, source][, place_id])