Already subscribe premium APIs but still 403 not authorized to access


#1

Here’s the part of code that run into 403 error:

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

retrying request; current status code: 403
retrying request; current status code: 403
retrying request; current status code: 403
HTTP Error code: 403: Forbidden: Authentication succeeded but account is not authorized to access this resource.
Rule payload: {‘query’: ‘bitcoin’, ‘maxResults’: 100}

I applied the developer account and it got through last week. My application environment is now in full archive/premium. Can you help me find where’s wrong or what happened with my account or app? My account is @michelle17058

Below is the detailed description of the error if it helps:

HTTPError Traceback (most recent call last)
in ()
1 tweets = collect_results(rule,
2 max_results=100,
----> 3 result_stream_args=premium_search_args)

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/searchtweets/result_stream.py in collect_results(rule, max_results, result_stream_args)
299 max_results=max_results,
300 **result_stream_args)
–> 301 return list(rs.stream())

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/searchtweets/result_stream.py in stream(self)
200 self.init_session()
201 self.check_counts()
–> 202 self.execute_request()
203 self.stream_started = True
204 while True:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/searchtweets/result_stream.py in execute_request(self)
251 resp = request(session=self.session,
252 url=self.endpoint,
–> 253 rule_payload=self.rule_payload)
254 self.n_requests += 1
255 ResultStream.session_request_counter += 1

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/searchtweets/result_stream.py in retried_func(*args, **kwargs)
99 logger.error(“HTTP Error code: {}: {}”.format(resp.status_code, error_message))
100 logger.error(“Rule payload: {}”.format(kwargs[“rule_payload”]))
–> 101 raise requests.exceptions.HTTPError
102
103 return resp

For the first trial, I use sandbox and it gives this error. Then I purchased Premium but still it gives the same error. Even I tried with the generated Bearer it gives similar error:
{
“error”: {
“message”: “Invalid or expired token.”,
“sent”: “2018-06-04T20:56:26+00:00”,
“transactionId”: “000a847500e5c1e9”
}
}

Thank you!


#2

@michelle17058 - Are you using the tokens associated with the app that you set up your dev environment with:
https://developer.twitter.com/en/account/environments


#3

Hi,

Yes, I am using the consumer key and secret generated with that app.


#4

And here’s my complete code if there is anything you feel may have a problem:

from searchtweets import ResultStream, gen_rule_payload, load_credentials
premium_search_args = load_credentials(“twitter_keys.yaml”,
yaml_key=“search_tweets_premium”,
env_overwrite=False)

rule = gen_rule_payload(“bitcoin”, 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) # change this if you need to

[print(tweet.all_text, end=’\n\n’) for tweet in tweets[0:10]];
[print(tweet.created_at_datetime) for tweet in tweets[0:10]];
[print(tweet.generator.get(“name”)) for tweet in tweets[0:10]];

Thanks.


#5

@michelle17058 You are probably setting your end point “label” wrongly.

Your endpoint Url should be like this:
https://api.twitter.com/1.1/tweets/search/:produtct/:label.json

WHERE
:product indicates the search endpoint you are making requests to, either 30day or fullarchive.
:label is the (case-sensitive) label associated with your search developer environment, as displayed at https://developer.twitter.com/en/account/environments.

Please, check your Dev environment label from this url https://developer.twitter.com/en/account/environments then edit your “twitter_keys.yaml” file credentials and set <END_POINT_URL> parameter properly for example:

https://api.twitter.com/1.1/tweets/search/30day /YourEnvironmentLabel.json


#6

@LeBraat we are having the same issue. We are using https://api.twitter.com/1.1/tweets/search/30day/dev.json as a endpoint url.


#7

Hi @TweetKitApp - If you’re getting a 403 - "Forbidden: Authentication succeeded but account is not authorized to access this resource" error, make sure that dev is the right label associated with your search developer environment. Follow the explanations in the post from Jun 26 for more information on how to do this.

Otherwise, could you tell us exactly what error is being returned?


#8