Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter premium not authorized

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='\n\n') 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?

like image 434
user1624577 Avatar asked Mar 26 '19 03:03

user1624577


Video Answer


1 Answers

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.

like image 150
YuaNWA Avatar answered Nov 06 '22 21:11

YuaNWA