【问题标题】:Determine twitter relationship via tweepy通过 tweepy 确定 twitter 关系
【发布时间】:2013-09-15 16:59:50
【问题描述】:

我正在寻找一种通过 tweepy 找出 twitter 用户之间关系的方法 我使用lookup_friendships() 来确定关系,但它总是给出真实的。这是我的代码:

import tweepy, time

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)

user = api.get_user("LeCorrector");

rel = api.lookup_friendships(screen_names=user.screen_name)

for x in rel:
    print(isinstance(x, tweepy.models.Relationship))

lookup_friendships 返回tweepy.models.Relationship objects 的列表,当我打印它们时,我总是正确的。 我的 tweepy 版本是 2.1。我找不到此功能的任何文档,所以我不确定我是否正确使用它。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    您正在打印检查类型并返回 TrueFalse 的 isinstance。如果您需要对象,则需要打印 x:

    类似:

    if(isinstance(x, tweepy.models.Relationship)):
        print x
    

    【讨论】:

    • 是的,你是对的,但这并没有多大帮助。现在它正在打印
    • 好吧,我还没有深入研究 tweepy,但基本上你需要访问你需要的 x 的属性。你基本上是在打印对象。像x.screen_name 这样的东西可能是。查看 print dir(x) 有哪些属性可用
    猜你喜欢
    • 2013-06-30
    • 2021-04-30
    • 2017-07-03
    • 2014-02-25
    • 2015-04-16
    • 2017-04-11
    • 2014-04-08
    • 1970-01-01
    • 2019-02-19
    相关资源
    最近更新 更多