Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I attempted to run the code below and am getting an error that states: HTTP Error code: 403: Forbidden: Authentication succeeded but account is not authorized to access this resource.

from searchtweets import ResultStream, gen_rule_payload, load_credentials, collect_results

import requests

premium_search_args = load_credentials("/home/dirname/twitter_keys.yaml",
                                       yaml_key="search_tweets_premium",
                                       env_overwrite=False)


rule = gen_rule_payload("basketball", results_per_call=100) # testing with a sandbox account
print(rule)

from searchtweets import collect_results

tweets = collect_results(rule, 
                         max_results=100, 
                         result_stream_args=premium_search_args)


# print(tweets.all_text)

[print(tweet.all_text, end='

') for tweet in tweets[0:10]];

My YAML file looks like this:

search_tweets_premium:
  account_type: premium
  endpoint: https://api.twitter.com/1.1/tweets/search/fullarchive/dev.json
  consumer_key: AAAAAAAAAAAAAAAAAAAAA
  consumer_secret: BBBBBBBBBBBBBBBBBBBBBBBBBBB

Only other thing to note is that I am using the free/sandbox service.

Any ideas if I am doing anything wrong in the code, the YAML, and/or within my Twitter developer account?

question from:https://stackoverflow.com/questions/65893047/authorization-error-403-with-twitter-api-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
320 views
Welcome To Ask or Share your Answers For Others

1 Answer

You'll need to go to https://developer.twitter.com/en/account/environments

https://developer.twitter.com/en/account/environments

There you should be able to see the various development environments that you have. You can create one should they not have been created.

The dev environment label would then be the thing you use to replace in your endpoint.

In my example, it would be: https://api.twitter.com/1.1/tweets/search/fullarchive/development.json

If that still doesn't work, you might need to include a bearer token in your YAML file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...