Twython使用企业搜索API

时间:2019-07-14 22:16:07

标签: python twitter tweepy twython

我正在尝试使用twython从Twitter抓取推文,并且我想为此使用企业搜索API,因为我想定义fromDate和toDate参数。

虽然我找不到任何方法,但是当我尝试从该日期起删除推文时,它仅返回大约14天后的推文。

twitter = Twython(consumer_token, access_token=ACCESS_TOKEN)
# Search parameters
def search_query(QUERY_TO_BE_SEARCHED):
    """
    QUERY_TO_BE_SEARCHED : text you want to search for 
    """
    df_dict=[]

    results = twitter.cursor(twitter.search, q=QUERY_TO_BE_SEARCHED,fromDate='2019071200',toDate='2019071400',count=100)
    for q in results:
        retweet_count = q['retweet_count']
        favs_count = q['favorite_count']
        date_created = q['created_at']
        text = q['text']
        hashtags = q['entities']['hashtags']
        user_name = '@'+str(q['user']['screen_name'])
        user_mentions = []
        if(len(q['entities']['user_mentions'])!=0):
            for n in q['entities']['user_mentions']:
                user_mentions.append(n['screen_name']) # Mentioned profile names in the tweet
        temp_dict = {'User ID':user_name,'Date':date_created,'Text':text,'Favorites':favs_count,'RTs':retweet_count,
                    'Hashtags':hashtags,'Mentions':user_mentions}
        df_dict.append(temp_dict)

    return pd.DataFrame(df_dict)

那是我的代码,您能帮我改善一下吗?

0 个答案:

没有答案