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:
- get the campaigns in your account, using the endpoint GET accounts/:account_id/campaigns and identify your campaign
- get the campaign’s line items (ad groups) using the endpoint GET accounts/:account_id/line_items and the
campaign_idsparameter from the previous step
- get that line item’s targeting using GET accounts/:account_id/targeting_criteria and the
line_item_idparameter 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
LOCATION, and that’s your location.
Glad to hear that, @oceangoplay!
Please mark an answer as being the solution, so others know this has been solved.
learning the API using PHP and C#.NET 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!
@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):
- You create an analytics job stating what you want to get
- 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
- Once it’s done, you get the analytics data using the job id, from the link in the job’s
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.
I have a new problem ！Hope to get your help！
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.
Oh,sorry I don’t know how to mark the topic already solved… 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.
Thank you, @juanshishido.