403 accessing Premium Sandbox with TwitterAPI


#1

Hi, I’m trying to search the Premium Sandbox using the TwitterAPI module here: https://github.com/geduldig/TwitterAPI/tree/master/examples

I get a 403 although my credentials are correct. My subscriptions show that I have Sandbox access to the Premium API. Is it necessary to activate this in some way?

Thanks in advance.


#2

We were able to get he Sandbox access working but just upgraded to the paid service, now we’re getting this error:


#3

Hi - have you added your app to your dev environment? You can check this in the dropdown menu on developer.twitter.com (top right) if you select dev environment (see screenshot below).

And could you confirm if you’re you using bearer token or user authentication?

23


#4

Thanks for such a quick reply.

Here is what we have. It doesnt authenticate in Postman, but using C#, we can authenticate but now get no data/results back when I know for sure that our parameters were returning data last night in the Sandbox.

We need to deliver data for a client and apply some analytics, any ideas?


#5

Can you please share your request with us to further investigate?


#6

I’ve now added my app to the development environment but I’m still getting the 403. I’m using the TwitterAPI module, which claims to be able to use the consumer keys and application tokens for authentication on the 30day and full-archive APIs: https://stackoverflow.com/questions/50272868/using-tweepy-to-access-twitters-premium-api


#7

Hi @domster71 - this package is not owned by us and it’s therefore difficult for me to help you troubleshoot.

I would suggest using Search Tweets, which is a TwitterDev owned Python wrapper that you can use to access the premium version of the API.


#8

Thanks, Aurelia. Could you possibly explain how I get the endpoint and bearer token for authentication? I was hoping to get around this.


#9

Hi @domster71 - have you reviewed our documentation on authentication and obtaining a bearer token?

And there are two endpoints: the data enpoint and the counts endpoint. You can read more about these in our documentation here.

Let us know if you have any more questions once you’ve reviewed these documents.


#10

Hi Aurelia, I’ve looked at that, but I’m looking for something that does a lot of the ‘heavy lifting’ of authentication for me, if I’m honest. Looking at this: https://github.com/twitterdev/search-tweets-python/blob/master/examples/api_example.rst , I should be able to connect using search-tweets with a twitter_keys.yml file passing username and password, is that correct? I’ve tried this but I’m getting 404s. Please could you confirm what the endpoint should be for the Enterprise full archive API? I should have access to the sandbox.


#11

Hi @domster71 - this endpoint is built for enterprise customers. If you’re just getting started, I would suggest looking at the premium version of the Search API. You will need to start by subscribing here: https://developer.twitter.com/en/account/subscriptions

You can then read our documentation to get started with the premium data endpoint: https://developer.twitter.com/en/docs/tweets/search/api-reference/premium-search.html


#12

Edit: I was including colons in the url, having removed this I am now getting results. Many thanks for your help, I will let you know if I encounter any more problems.

Hi Aurelia, thank you for your reply. I’m trying to twurl to “/1.1/tweets/search/:fullarchive/:development.json” plus the query-string, and getting the response “Forbidden: Authentication succeeded but account is not authorized to access this resource.”. According to my Subscriptions page, I have Sandbox access to the full archive. ‘development’ is the label associated to my full-archive sandbox access on my Subscriptions page.

Thanks

Dom


#13

Hi, I’m trying to get historical tweets using the Premium Sandbox full archive access, but I get the response that fromDate and toDate are not valid operators. Are these not available through sandbox access? Please let me know if you would prefer me to open a new ticket.


#14

It would be easiest for us to troubleshoot this if you provided an example of your request in full (making sure to keep your keys private).

Here is an example of a curl request that you could use to hit this endpoint:

curl --request POST \ --url https://api.twitter.com/1.1/tweets/search/fullarchive/{ENVIRONMENT_NAME}.json \ --header 'authorization: Bearer {BEARER_TOKEN}' \ --header 'content-type: application/json' \ --data '{ "query":"from:TwitterDev lang:en", "maxResults": "500", "fromDate":"{YYYYMMDDHHmm}", "toDate":"{YYYYMMDDHHmm}" }'

Just replace {ENVIRONMENT_NAME}, {BEARER_TOKEN}, and {YYYYMMDDHHmm} with your relevant information.

If you are still experiencing issues with the bearer token, please use the following cUrl command:

curl -u '{API_KEY}:{API_SECRET_KEY}' \ --data 'grant_type=client_credentials' \ 'https://api.twitter.com/oauth2/token'

Making sure to replace {API_KEY} and {API_SECRET_KEY} with those tokens that are associated to the Twitter app that you have associated with this product in the dev environments page.

Might I also suggest that you try playing around with Insomnia? It has worked very well for my team in making requests to REST endpoints.


#15

Hi, thanks for the detailed reply. I’m running twurl from a Windows command line at the moment, so the command:

twurl “/1.1/tweets/search/fullarchive/development.json?query=place_country:us lang:en”

works fine, but if I add fromDate and toDate eg:

twurl “/1.1/tweets/search/fullarchive/development.json?query=place_country:us lang:en fromDate:201701010000 toDate:201701020000”

I get the response:

“message”:"There were errors processing your request: Reference to invalid operator ‘toDate’. Operator is not available in current product or product packaging. Please refer to complete available operator list at http://t.co/operators. (at position 48), Reference to invalid field ‘fromDate’ (at position 26), Reference to invalid operator ‘fromDate’. Operator is not available in current product or product packaging.

fromDate and toDate are not in the operator list on the page linked to, but I have seen them as the operators to use for historic tweets.

Thanks,

Dom


#16

Try using this instead:

twurl -t -A "Content-Type: application/json" -d '{"query":"keyword place_country:us lang:en","maxResults":"500","fromDate":"201701010000","toDate":"201701020000" }' "/1.1/tweets/search/fullarchive/development.json"