为什么我只阅读主页时间线会出现禁止错误?
Why I get forbidden error for only reading home timeline?
我的代码就这么简单,但它给了我 403 错误:
def init_api():
api = json.load(open('secret.json'))['twitterapi']
consumer_key = api['api_token']
consumer_secret = api['api_secret']
access_token = api["access_token"]
access_token_secret = api["access_secret"]
bearer_token = api["bearer_token"]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#Step 2 - Retrieve Tweets
public_tweets = api.home_timeline()
for tweet in public_tweets:
print(tweet.text)
if __name__ == "__main__":
init_api()
Traceback (most recent call last):
File "path/to/project/config.py", line 45, in <module>
init_api()
File "path/to/project/config.py", line 39, in init_api
public_tweets = api.home_timeline()
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 488, in home_timeline
return self.request(
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 259, in request
raise Forbidden(resp)
tweepy.errors.Forbidden: 403 Forbidden
453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve
(venv)
来自错误信息:
453 - You currently have Essential access which includes access to Twitter API v2 endpoints only.
因此,您只能使用 v2 端点,但 api.home_timeline()
是 v1.1 API,因此 reading the timeline is 的 v2 端点:
GET /2/users/:id/tweets
或者,由于您使用的是 tweepy
,因此请使用 their v2 API
Client.get_users_tweets(id, *, end_time=None, exclude=None, expansions=None, max_results=None,
media_fields=None, pagination_token=None, place_fields=None, poll_fields=None,
since_id=None, start_time=None, tweet_fields=None, until_id=None,
user_fields=None, user_auth=False)
请求提升 v1.1 访问权限。它通常会立即或很快被接受。不过可能无法解决您的问题,因为自从他们将 StreamListener 折叠到 Stream 中以来,我自己似乎无法弄清楚。
我的代码就这么简单,但它给了我 403 错误:
def init_api():
api = json.load(open('secret.json'))['twitterapi']
consumer_key = api['api_token']
consumer_secret = api['api_secret']
access_token = api["access_token"]
access_token_secret = api["access_secret"]
bearer_token = api["bearer_token"]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#Step 2 - Retrieve Tweets
public_tweets = api.home_timeline()
for tweet in public_tweets:
print(tweet.text)
if __name__ == "__main__":
init_api()
Traceback (most recent call last):
File "path/to/project/config.py", line 45, in <module>
init_api()
File "path/to/project/config.py", line 39, in init_api
public_tweets = api.home_timeline()
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 488, in home_timeline
return self.request(
File "path/to/project/venv/lib64/python3.10/site-packages/tweepy/api.py", line 259, in request
raise Forbidden(resp)
tweepy.errors.Forbidden: 403 Forbidden
453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve
(venv)
来自错误信息:
453 - You currently have Essential access which includes access to Twitter API v2 endpoints only.
因此,您只能使用 v2 端点,但 api.home_timeline()
是 v1.1 API,因此 reading the timeline is 的 v2 端点:
GET /2/users/:id/tweets
或者,由于您使用的是 tweepy
,因此请使用 their v2 API
Client.get_users_tweets(id, *, end_time=None, exclude=None, expansions=None, max_results=None,
media_fields=None, pagination_token=None, place_fields=None, poll_fields=None,
since_id=None, start_time=None, tweet_fields=None, until_id=None,
user_fields=None, user_auth=False)
请求提升 v1.1 访问权限。它通常会立即或很快被接受。不过可能无法解决您的问题,因为自从他们将 StreamListener 折叠到 Stream 中以来,我自己似乎无法弄清楚。