How to get the location of audience in twitter campaign


How to get the location of audience in twitter campaign with api ? i can see country in web, campaign -> audience -> location.


Hi @oceangoplay! Assuming you went through the authorization flow and you’ve got the token and token secret, and that you’re using some library to interact with the Twitter Ads API, you should:

  1. get the campaigns in your account, using the endpoint GET accounts/:account_id/campaigns and identify your campaign
  2. get the campaign’s line items (ad groups) using the endpoint GET accounts/:account_id/line_items and the campaign_ids parameter from the previous step
  3. get that line item’s targeting using GET accounts/:account_id/targeting_criteria and the line_item_id parameter from the previous step (a campaign can actually have more than one line item if they were created through the API, but usually there is just one), and then loop through all the targeting criteria and identify those with targeting_type = LOCATION, and that’s your location. :slight_smile:


Hi @majoritasdev! Thank you for your prompt answer, the problem was solved!!!:grinning:


Glad to hear that, @oceangoplay! :slight_smile:

Please mark an answer as being the solution, so others know this has been solved.

Thank you!


learning the API using PHP and C#.NET :sunglasses: this helps.


Hi @majoritasdev !

I have a new problem !
I can get the total spend, Impressions or other data. But I want to be able to separate data by country.
get the data.

what should I do? Use country and analysis association?


@jeffld: glad to hear that! :slight_smile:

@oceangoplay: please read the Segmentation Reporting section at And you can find the API endpoints to use, at The idea is that if you need analytics data segmented by something, like broken down by country, you have to use the asynchronous approach, which is a 2-step process, actually a 3-step process (counting the intermediate step of checking the job status):

  1. You create an analytics job stating what you want to get
  2. You check the created job’s status regulaly, at a certain time interval of your choice, to see if it’s done collecting all the data you requested
  3. Once it’s done, you get the analytics data using the job id, from the link in the job’s url parameter.

Also, please note the following, when getting the data from the url received:

Asynchronous result files are compressed (gzip) to optimize transfers, and must be uncompressed before access. Because of this, the Accept-encoding: gzip header is required for requests to the asynchronous analytics endpoint.

You can also find other useful information about the asynchronous approach at under Analytics Implementation Details.

Good luck! :slight_smile:


Hi @majoritasdev!
I have a new problem !Hope to get your help!:grinning:
Why are the data obtained using synchronous and asynchronous methods different?
I use the asynchronous method to get a month’s data, but there is a small difference with the background data. about app


Hi @oceangoplay! I don’t know. Is the month you’re getting data for the current month? Because if it is, maybe the data got from a synchronous endpoint is more up to date than the data from an asynchronous endpoint. Because the docs mention “real-time” when they talk about the synchronous endpoints and they don’t mention it when they talk about the asynchronous endpoints.


@oceangoplay: can you please mark this topic as solved, and open a new topic for each new type of problem you encounter? Just like you did for the last question.

Thank you.


Oh,sorry I don’t know how to mark the topic already solved…:sweat_smile: not find


@oceangoplay: For every reply in the topics you started you will see an additional icon in the bottom right corner, specifically a checked checkbox, near the other actions like “Reply”, “flag”, “like”, etc., and you just check that for the reply that you consider solves your original question. (see in the image below)


Now, someone from the Twitter Staff marked this topic as solved, but just so you know for the future. :slight_smile:

Thank you, @juanshishido. :slight_smile: