如何使用 Twython 获取所有直接消息? [英] How to fetch all the direct messages using Twython?

查看:33
本文介绍了如何使用 Twython 获取所有直接消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取我帐户中的所有直接消息.但我尝试使用游标进行获取.但我收到了类似

I am trying to fetch all the direct messages in my account. But I tried to use cursor for fetching. But I'm getting an error like

TypeError: cursor() missing 1 required positional argument: 'function'

我的代码如下.

from twython import Twython

APP_KEY = 'KEY'
APP_SECRET = 'SECRET'
ACCESS_TOKEN = 'TOKEN'
ACCESS_SECRET = 'SECRET'

twitter = Twython(APP_KEY,APP_SECRET,ACCESS_TOKEN,ACCESS_SECRET)

for tweet in Twython.cursor(twitter.get_direct_messages(),since_id=1,count=100):
print (tweet)

请帮忙解决这个问题.

推荐答案

很确定您需要在 twitter 对象上调用 .cursor 方法,而不是在Twython 类.

Pretty sure that you need to invoke the .cursor method on the twitter object, not on the Twython class.

所以试试

for tweet in twitter.cursor(twitter.get_direct_messages(),since_id=1,count=100):
    print (tweet)

具体来说,这对我有用:

Specifically, this works for me:

results = twitter.cursor(twitter.get_direct_messages,count=2)
for result in results:
     print result['text']

这篇关于如何使用 Twython 获取所有直接消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆