首页 > 解决方案 > Tweepy 库不显示数据

问题描述

在我的python Flask解决方案中,我tweepy实现了一个模块,以便仅显示我帐户中的一些流行推文和推文。在从官方文档中成功实现代码后,我遇到了一个不时发生的奇怪错误——推文也没有显示在页面和终端中。你可以在下面看到我的代码。

    auth = tweepy.OAuthHandler(
        'myID', 'mySecret')
    auth.set_access_token(
        'myToken', 'myTokenSecret')
    api = tweepy.API(auth)
    api.secure = True
    search = request.args.get('q')
    public_tweets = api.user_timeline(search)

    covid_tweets = api.search(q="Sombor Tweets")
    for tweet in covid_tweets:
        print(tweet.text.encode("utf-8"))
...
return render_template('home.html', tweets=public_tweets, sombortweets =covid_tweets)

{% for tweet in tweets %}
        <div class="card mt-2">
          <div class="card-body">
            <div class="card-text">
              {{ tweet._json.text }}
            </div>
          </div>
        </div>
{% endfor %}

{% for tweet in sombortweets %}
        <div class="card mt-2">
          <div class="card-body">
            <div class="card-text">
              {{ tweet._json.text }}
            </div>
          </div>
        </div>
{% endfor %}

我期待你的回答,我希望有人遇到同样的情况。问候。

标签: pythonflasktweepy

解决方案


推荐阅读