Trouble Getting Started with Premium Search API


#1

I’m having a bit of trouble getting started with the Premium Search API. I’ve made an environment, installed cURL, and retrieved my Bearer token. But I can’t figure out how to retrieve counts data.

When I enter in the following code (using my actual token)…

curl --request POST
–url https://api.twitter.com/1.1/tweets/search/fullarchive/research/counts.json
–header ‘authorization: Bearer TOKEN’
–header ‘content-type: application/json’
–data ‘{
"query”:”brecht AND trump AND (dark times)”,
“fromDate”:“201501010000”,
“toDate”:"201901010000”
“bucket”: “month”
}’

I get this error: {“error”:{“message”:“Invalid json, could not parse.”,“sent”:“2019-02-20T21:21:50+00:00”,“transactionId”:“00c36b7d002e6b25”}}

Or when I use this query…

curl -X POST “https://api.twitter.com/1.1/tweets/search/:product/:label/counts.json” -d '{“query”:”(brecht AND trump AND (dark times))”,”fromDate”:"<201501010000>",“toDate”:"<201902150000>","bucket”:”month”}’ -H “Authorization: Bearer TOKEN”

… it just goes to the next line. How do I retrieve my data? Thanks!


#2

It’s possible, but significantly more complicated to use just plain curl for this. (In your call i think the issue might be the extra < and > in the dates)

It might be easier to use the command line tool from: https://github.com/twitterdev/search-tweets-python#using-the-comand-line-application

Once installed, you can run

python search_tweets.py \
--credential-file twitter_keys.yaml \
--max-results 100 \
--results-per-call 100 \
--filter-rule "(brecht AND trump AND (dark times))" \
--start-datetime 2015-01-01 \
--end-datetime 2019-01-01 \
--filename-prefix test_search \

Running that assumes you have python 3 installed, and there is a twitter_keys.yaml file in the directory (like the github readme describes). It will save a test_search.json file with results.


closed #3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.