Twitter premium not authorized
Asked Answered
U

1

6

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?

Unanswerable answered 26/3, 2019 at 3:33 Comment(4)
I am using the free/sandbox service Then why are you trying to access a premium url?Ledoux
Good catch @JohnGordon. I did not realize that. I tried changing it to a few different URLs that I found and so far same results. I do think you're probably on to the root of the problem though.Unanswerable
Sandbox provides access to the premium APIs, but at a lower volume and without some additional features such as counts. This should work, assuming that you have a developer environment configured that is named "dev" in the developer dashboard.Trembly
@AndyPiper - I do have a developer dashboard but I do not know the name of it? Is that going to be the same as the application name? My previous experience was using Tweepy and it was so much simpler :/Unanswerable
A
10

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.

Aylmer answered 25/7, 2019 at 15:58 Comment(2)
thanks it seems the name "development" is important.Ridiculous
To add to this, it seems that the dev environments are now not enabled by default. Going to developer.twitter.com/en/account/environments allows you to enable them and to choose the appropriate label.Retrochoir

© 2022 - 2024 — McMap. All rights reserved.