The Ads API program enables businesses to create and manage ad campaigns programmatically on Twitter. To help achieve your business goals, the Ads API provides the following suite of tools: Objective-based campaigns, analytics, and targeting.
Twurl is a curl-like application, tailored specifically for the Twitter API. It knows how to grant an access token to a Twitter app for a specified user and then sign all requests with that access token. It also provides other development and debugging conveniences such as defining aliases for common requests, as well as support for multiple access tokens to easily switch between different Twitter apps and Twitter accounts.
Twurl can be installed using RubyGems as follows:
gem install twurl
After you have twurl installed, you can authorize your Twitter app and Twitter account using your consumer key and its secret.
twurl authorize --consumer-key key --consumer-secret secret
This will return a URL that you should open up in your browser. Authenticate to Twitter, and then enter the returned PIN back into the terminal. Assuming all that works well, your account will be authorized to make requests with the API.
The simplest request just requires that you specify the host and the path you want to request.
Similar to curl, a GET request is performed by default.
twurl -H "https://ads-api.twitter.com" "/5/accounts/"
You can also pipe the returned response into jq, which gives you a nicely formatted output, as well as some additional format options.
twurl -H "https://ads-api.twitter.com" "/5/accounts/" | jq .
One more handy thing which is worth mention is that by passing the -t or –trace to twurl you can get a full trace of your request, including headers:
twurl -t -H "https://ads-api.twitter.com" "/5/accounts/" | jq .
Using twurl is also very helpful when you’re on Ads API forums to discuss or ask about any API behavior that you think might not be working quite right. Providing a twurl request that reproduces the behavior you are seeing will provide a clear and standardized format that facilitates the discussion.
To find out more about twurl and its options, run twurl --help or visit twurl’s GitHub page. Be sure to check out this blog post on the subject for further inspiration.