How to get the location of audience in twitter campaign

api

#1

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


#2

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:

#3

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


#4

Glad to hear that, @oceangoplay! :slight_smile:

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

Thank you!


#5

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


#6

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.
eg:

what should I do? Use country and analysis association?
Thanks!:grinning:


#7

@jeffld: glad to hear that! :slight_smile:

@oceangoplay: please read the Segmentation Reporting section at https://developer.twitter.com/en/docs/ads/analytics/overview. And you can find the API endpoints to use, at https://developer.twitter.com/en/docs/ads/analytics/api-reference/asynchronous. 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 https://developer.twitter.com/en/docs/ads/analytics/overview under Analytics Implementation Details.

Good luck! :slight_smile:


#8

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


#9

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.


#10

@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.


#11

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


#12

@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)

marking-as-solved

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: