Last active
May 17, 2019 18:06
-
-
Save jcipriano/aa435ff74c97746da3ca49115cdb6ecc to your computer and use it in GitHub Desktop.
Basic Twitter Ads API requests with Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request') | |
// twitter authentication | |
var twitter_oauth = { | |
consumer_key: 'your-consumer-key', | |
consumer_secret: 'your-consumer-secret', | |
token: 'your-access-token', | |
token_secret: 'your-access-token-secret' | |
} | |
// update request options | |
request_options = { | |
url: 'https://ads-api.twitter.com/5/accounts', | |
oauth: twitter_oauth | |
} | |
// request all acessible ad accounts | |
request.get(request_options, function (error, response, body) { | |
if (error) { | |
console.log(error) | |
return; | |
} | |
console.log(body) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request') | |
// twitter authentication | |
var twitter_oauth = { | |
consumer_key: 'your-consumer-key', | |
consumer_secret: 'your-consumer-secret', | |
token: 'your-access-token', | |
token_secret: 'your-access-token-secret' | |
} | |
// update request options (replace account ID in resource URL) | |
request_options = { | |
url: 'https://ads-api.twitter.com/5/stats/jobs/accounts/18ce53w996p', | |
oauth: twitter_oauth | |
} | |
// add request params (example request) | |
request_options.formData = { | |
start_time: '2019-02-01', | |
end_time: '2019-04-30', | |
entity: 'ORGANIC_TWEET', | |
entity_ids: '1118937029411131392', | |
granularity: 'DAY', | |
metric_groups: 'ENGAGEMENT', | |
placement: 'ALL_ON_TWITTER', | |
} | |
// create an analytics job | |
request.post(request_options, function (error, response, body) { | |
if (error) { | |
console.log(error) | |
return; | |
} | |
console.log(body) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request') | |
// twitter authentication | |
var twitter_oauth = { | |
consumer_key: 'your-consumer-key', | |
consumer_secret: 'your-consumer-secret', | |
token: 'your-access-token', | |
token_secret: 'your-access-token-secret' | |
} | |
// update request options | |
request_options = { | |
url: 'https://ads-api.twitter.com/5/stats/jobs/accounts/18ce53w996p', | |
oauth: twitter_oauth | |
} | |
// request all analyitics jobs and their status | |
request.get(request_options, function (error, response, body) { | |
if (error) { | |
console.log(error) | |
return; | |
} | |
console.log(body) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment