Premium API endpoint


hi everyone
I am writing using translation software,
English may be a little strange,sorry

Search api
I created an application that works normally
endpoint is

Today ,i buy Premium Api 30day ,
I saw this webpage
this webpage has been written

If you are using the 30-day endpoint:

my Dev environment label is [SnsTwitter]
I have changed “my_env_name” to “SnsTwitter”.
Edited endpoint is

I thought that it would work normally changing the endpoint, but HTTP Status Codes is 422
Is there anything missing to be HTTP Status Codes 200?

Please let me know f you need more information.
Thanks for your help!


i am reading

how do you make or set YAML file ?


Hi, @csar19783364. I see the cause of the 422 status. Your URL appears to be for the correct endpoint, but it must have a query. Twitter does not know what to send you as a response, because you have not specified, in a query.

You will see, in the docs, that query is required (under the section: Data request parameters)

Instead of just:


The Twitter API response to the first request, without a query, does pinpoint the issue.

HTTP/1.1 422 Unprocessable Entity
content-type: application/json; charset=utf-8
date: Thu, 08 Feb 2018 15:18:36 GMT
UTC; Path=/;

{"error":{"message":"There were errors processing your request: Missing required parameter:'query', Missing required parameter:'query'","sent":"2018-02-08T15:18:36+00:00","transactionId":"00473ca4002e88c"}}

It is worth receiving the API response body for the error message, as well as the status code returned.


Hi, @lxcichano .
Thank you for replying and help

I understood that the end point is not wrong

I uesd this query ,
I doubt the query,query will be wrong

Probably such this query, I will make it and try it
"" -d ‘{“query”:"(snow)",“fromDate”:“201709270000”, “toDate”:“201709280000”, “maxResults”:10}’ -H "Authorization: Bearer TOKEN

I may come back and ask you again,
Thank you


Hi, @csar19783364. I notice that you used the letter q (q=abc+) instead of the word query (query=abc+) in your query.

In your second query, you do show the whole word query (-d ‘{“query”:"(snow)"). I think that should work.

This example comes from the docs (Note the use of the whole word query):

curl "<yyyymmddhhmm>&toDate=<yyyymmddhhmm>" -H "Authorization: Bearer TOKEN"

…On this page:


Hi, @lxcichano .
Thank you for replying again ,help and advice

First of all, I will do my best until Curl passes.
Then I will think about Python code.

docs POST example is

curl -X POST “” -d
’{“query”:“TwitterDev “search api””,“maxResults”:“500”,“fromDate”:“yyyymmddhhmm”,
“toDate”:“yyyymmddhhmm”}’ -H “Authorization:
Bearer TOKEN”

I changed Below ,From POST example
:product → 30day
:label → SnsTwitter
yyyymmddhhmm(fromDate) → 201802010000
yyyymmddhhmm(toDate) → 201802020000
TOKEN → 999999999999999999-AAAAAAAAAAAAAAAAAAAAAA(My Access Token)
“query”:“TwitterDev “search api”” → “query”:“snow”

The Curl command should be like this

curl -X POST “” -d ‘{“query”:“snow”,“maxResults”:“500”,“fromDate”:“201802010000”,
“toDate”:“201802020000”}’ -H “Authorization:
Bearer 999999999999999999-AAAAAAAAAAAAAAAAAAAAAA(My Access Token)”

but ,The response is this
{“error”:{“message”:“Invalid or expired token.”,“sent”:“2018-02-10T15:18:08+00:00”,“transactionId”:“003b61cd0028d019”}}

Can I authenticate with access token only?
Please give me some advice.
Thank you


Hi, @lxcichano .
Thank you for replying again ,help and advice

My program Request succeeded !!

I appreciate it very much.
After all the query in the code was a problem


Congratulations, @csar19783364! That is great news. Could you please share the successful curl command with us so we can learn from it, too?



Hi, @lxcichano .
Thank you for replying again .

My program Request succeeded,
but I do not know Curl command request yet,sorry


Hello @csar19783364 ,

I guess what @lxcichano asked is what you corrected in this line of code that worked.
"curl -X POST “” -d ‘{“query”:“snow”,“maxResults”:“500”,“fromDate”:“201802010000”,
“toDate”:“201802020000”}’ -H “Authorization:
Bearer 999999999999999999-AAAAAAAAAAAAAAAAAAAAAA(My Access Token)”

I’m in a similar fix and your successful code might just help.

I got a lame question though: Who knows how the Bearer Token is gotten? Just can’t find information about it anywhere.



Hello, @ibksolar. Here is the Twitter developers’ bearer token info:



Thanks a bunch for your reply. I am a newbie and I’ve been struggling for over a week to get things done. I’m still trying to grasp couple of things.
I have been on this page earlier but couldn’t make sense of the documentation. The syntax is

POST /oauth2/token HTTP/1.1
User-Agent: My Twitter App v1.0.23
Authorization: Basic eHZ6MWV2R … o4OERSZHlPZw==
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 29
Accept-Encoding: gzip


First, what language is this written? Is this Python?

Python has a “pycurl.Curl” library/method, is it the same as the "curl -X POST “” " ?


@ibksolar, the example request and response shown would be in HTTP. They are the request and response that you would see in an HTTP inspector, like Fiddler or Wireshark, or a browser’s dev toolbar “network” tab.

You can construct “raw” HTTP posts in tools like Fiddler and Postman. Or, you can construct them in higher level programming languages, like C# or Python.

I’ve coded this in C# on my own, but I now use a library called TweetInvi, which makes it easy to accomplish.

, Lee


Thanks for your prompt reply @lxcichano . Can you please tell me that how can I run following code in python, because this is not python syntax. I’d tried but found errors.

require 'net/http’
require ‘uri’

uri = URI.parse(“”)

headers = {“Authorization”:“Bearer MYREALLYLONGTOKENBASEDONKEYS”, “Content-Type”: “application/json”}

data = {“query”:"{snow OR sleet OR hail OR (freezing rain)) has:images", “fromDate”:“201709270000”,“toDate”:“201709280000”}

http =, uri.port)
request =, headers)
request.body = data

response = http.request(request)

This is the code I’d taken from Twitter Official help.
P.s. I’d done all pre-requisites steps but through this I can’t having extracted tweets.

Can you please help me? or send a online resource?


Hello, @umairhanif00. Your posted code appears to be Ruby. The first detail I notice is that your uri is parsing an SSL endpoint (HTTPS), but your response is not using SSL.

 uri = URI.parse(“”)
response = http.request(request)

This post might help you:

You could also try this converter:


I’d taken help from this link Application-auth. Copied all the stuff and modified the consumer and consumer secret keys.

When I use,

SEARCH_TWEETS_URL = ‘’ # this is standard endpoint
it gives me all the tweets which I am asking


When I change this to,
SEARCH_TWEETS_URL = '‘’ # This is Premium Search endpoint mentioned at Twitter documentation.

It gives me error of invalid request / token.

Can you please tell me where exactly I am doing a mistake?
Thanks :slight_smile: Anxiously waiting for your reply.


Hello, @umairhanif00. In your SEARCH_TWEETS_URL, what looks like the name of the JSON file (/development.json) should match your ‘Dev environment label’. Does it?


Yes my environment label is ‘development’


Are you using the headers and payload variables from that sample code?

It would help to see those, too, but don’t post your actual token. It is hard to troubleshoot code without seeing your code.


headers = {‘Authorization’: ‘Bearer {}’.format(access_token)}
payload = {‘q’: ‘PSL’, ‘count’: 10, ‘result_type’: ‘popular’}

access_token is coming from above code snippet

Sorry for the inconvenience caused, I am from cellphone and can give you this assistance. Will post you the code early in the morning. Can you please tell me through this?