Search code examples
twitterendpointtwurl

Count number of Tweets from the past 30 days using Twurl


To request tweets from the Standard search API with a specific hashtag, I've done

twurl "/1.1/search/tweets.json?q=#jesus"

Tht worked fine. Now wanting to use the Premium search APIs to count the tweets from the past 30 days with the hashtag jesus.

In it, there's a Counts endpoint, /search/:label/counts.

For the tweets from the past 30 days, that's the endpoint pattern, /search/30day/:label/counts.json.

I've created a Search Tweets: 30-Days Sandbox with name stackoverflow (that is the label).

Then, when running the following

twurl "/1.1/tweets/search/30day/stackoverflow/counts.json?query=#jesus"

I get

{"error":{"message":"Unauthorized: Stream is not enabled for count requests","sent":"2020-02-26T13:26:57+00:00","transactionId":"00f67ea10058270b"}}

From this, decided to go to the app keys and tokens and regenerated both Consumer API keys and Access token & access token secret.

After

twurl authorize --consumer-key ************** --consumer-secret *****************

and using the PIN code I get

Authorization successful

If I do again

twurl "/1.1/tweets/search/30day/stackoverflow/counts.json?query=#jesus"

Then get

{"error":{"message":"Invalid or expired token.","sent":"2020-02-26T13:39:44+00:00","transactionId":"00dea42000a8a098"}}

Regenerated again both Consumer API keys and Access token & access token secret but still no success.

How can I do it then?


Solution

  • Counts is only available to paid premium accounts, and one needs to pay for premium access.

    Use this link to Apply for access.