python - 如何修复 suggest_users() 中的 Tweepy 错误 'Sorry, that page does not exist.'

标签 python python-3.x twitter tweepy

我正在使用 tweepy==3.6.0 和 Python 3.6

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(access_token,
                          access_token_secret)
api = tweepy.API(auth)

# categories = api.suggested_categories()
users = api.suggested_users(slug='science')

suggested_users() 引发此错误:

raise TweepError(error_msg, resp, api_code=api_error_code) tweepy.error.TweepError: [{'code': 34, 'message': 'Sorry, that page does not exist.'}]

最佳答案

基于Twitter API reference , GET users/suggestions/:slug 用于:

Access the users in a given category of the Twitter suggested user list.

因此,当使用api.suggested_users()时,您不能指定像“科学”这样的任意类别。您需要从建议类别之一获取类别别名,您可以使用 api.suggested_categories() 检索该类别。

下面是一个工作示例,其中列出了第一个建议类别的用户(使用 categories[0].slug):

categories = api.suggested_categories(lang='en')
# print names and slugs of suggested categories
for cat in categories:
    print(cat.name,' - ',cat.slug)

users = api.suggested_users(slug=categories[0].slug, lang='en')
# print id and screen names of suggested users
for user in users:
    print(user.id, ' - ', user.screen_name)

关于python - 如何修复 suggest_users() 中的 Tweepy 错误 'Sorry, that page does not exist.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55781495/

相关文章:

python - 在 python 3 中用换行符写入文件

python - matplotlib:设置主要和次要刻度线强制相同的 x 和 y 刻度

python - Mechanize 406错误

Python3 四舍五入到最接近的偶数

python - 在 Python3 中使用 cookie 处理程序处理站点请求的正确方法是什么?

python - 如何使用 MultiIndex.from_product 重新索引?

python - 用于获取链接的 Beautifulsoup 和 Soupstrainer 不适用于 hasattr,始终返回 true

javascript - 改变 iframe 的宽度

javascript - 从 twitter api 获取错误的身份验证数据 | Angular 2

Android Intent startActivityForResult 未正确返回