[英]Reply to Tweet with Tweepy - Python
我似乎無法回復特定的推文:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
### at this point I've grabbed the tweet and loaded it to JSON...
tweetId = tweet['results'][0]['id']
api.update_status('My status update',tweetId)
api 表示它采用可選參數,in_reply_to_status_id 是第一個,但它似乎完全忽略了它。 此腳本將發布更新狀態,但不會將其鏈接為對我傳遞的 tweetId 的回復。
API 供參考:http://code.google.com/p/tweepy/wiki/APIReference#update_status
有人有主意嗎? 我覺得我在這里缺少一些簡單的東西......
提前致謝。
我遇到了同樣的問題,但幸運的是我找到了解決方案。 你只需要在推文中包含用戶的 screen_name :
api.update_status('@<username> My status update', tweetId)
只是發布解決方案,所以沒有其他人像我那樣受苦。 Twitter 更新了 API 並添加了一個名為auto_populate_reply_metadata
的選項
您需要做的就是將其設置為 true,其余的保持原樣。 這是一個示例:
api.update_status(status = 'your reply', in_reply_to_status_id = tweetid , auto_populate_reply_metadata=True)
此外,status_id 是推文 URL 末尾的一長串數字。 祝你好運!
你也可以這樣做
api.update_status("my update", in_reply_to_status_id = tweetid)
那么,這很簡單。 我必須使用@ 表示法指定推文的對象是誰。
api.update_status('My status update @whoIReplyTo',tweetId)
我發現在指定我正在回復的推文時,我必須包含推文的 ID 字符串(而不是實際的 ID 號)
api.update_status('@whoIReplyTo my reply tweet',tweetIdString)
這似乎是 Tweepy 中的一個錯誤——即使您使用正確的參數集調用api.update_status ,
api.update_status(status=your_status, in_reply_to_status=tweet_to_reply_to.id)
這條推文不會是回復。 為了獲得回復,您需要提及要回復的用戶並指定正確的 in_reply_to_status id。
reply_status = "@%s %s" % (username_to_reply_to, your_status)
api.update_status(status=reply_status, in_reply_to_status=tweet_to_reply_to.id)
不過請記住——Tweepy 和 Twitter 的服務器仍然強制執行最多 140 個字符,所以一定要檢查一下
len(reply_status) <= 140
同樣,我認為這是一個錯誤,因為在 Twitter 應用程序上,您可以回復而不嵌入您回復的人的用戶名。
reply_status = "@%s %s" % (tweet.user.screen_name, "type your reply here")
api.update_status(status=reply_status, in_reply_to_status_id=tweet.id)
這是最后一個正確的形式,我幾分鍾前剛測試過
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.