Get "interests" of a given campaign

targeting
campaign-management

#1

We are building a tool to give our clients information about the campaigns their agencies are activating.

It would be important for us if we could provide them the segmentation chosen for a given activated campaing.

We can get all the promoted tweets, but didnt have any luck finding this information.

Is there any endpoint able to provide that?


#2

Hi @controledash! What you want is to get the targeting options, which are set on the line item. So you must first get the line items and see which one has the campaign_id property equal to the campaign’s twitter id, and then you use the endpoint GET accounts/:account_id/targeting_criteria with the parameter line_item_id equal to the line item id found earlier, and you get all the targeting options, among which you can find the campaign interests, if it has any.

Below, it’s my PHP function that I use to get all line items, maybe you find it useful:

function getLineItems () {
	global $tw, $twAccount;

	$allLineItems = array();
	$params = array('with_deleted' => true, 'sort_by' => 'created_at-asc');
	$lineItems = $tw->get('accounts/' . $twAccount['id_tw_account'] . '/line_items', $params);

	while (!empty($lineItems) && empty($lineItems->error) && !empty($lineItems->data)) {
		$allLineItems = array_merge($allLineItems, $lineItems->data);

		if (empty($lineItems->next_cursor)) {
			break;
		}

		$lineItems = $tw->get('accounts/' . $twAccount['id_tw_account'] . '/line_items', array_merge($params, array('cursor' => $lineItems->next_cursor)));
	}

	return $allLineItems;
}

#3

Tks majoritasdev!
That helped a lot!!!