How to get ad account ID and campaigns using access token


#1

How do I get the account ID of an ad account and access its campaigns using access token after generating the same?


#2

@SilverPush: To retrieve the advertising-enabled accounts that the authenticating user has access to, use the GET accounts endpoint and look for the id attribute.

To access its campaigns, use the GET accounts/:account_id/campaigns endpoint.

Below is an example.

To get the accounts:

$ twurl -H ads-api.twitter.com "/1/accounts/" | jq
{
  "request": {
    "params": {}
  },
  "data": [
    {
      "name": "API McTestface",
      "business_name": null,
      "timezone": "America/Los_Angeles",
      "timezone_switch_at": "2016-07-21T07:00:00Z",
      "id": "18ce54d4x5t",
      "created_at": "2016-07-21T22:42:09Z",
      "salt": "54cb7b5a34183f77d82dd6d0f4329691",
      "updated_at": "2016-12-25T08:20:40Z",
      "business_id": null,
      "approval_status": "ACCEPTED",
      "deleted": false
    }
  ],
  "data_type": "account",
  "total_count": 1,
  "next_cursor": null
}

The account ID is 18ce54d4x5t.

To get the campaigns:

$ twurl -H ads-api.twitter.com "/1/accounts/18ce54d4x5t/campaigns" | jq
{
  "request": {
    "params": {
      "account_id": "18ce54d4x5t"
    }
  },
  "data": [
    {
      "name": "example-campaign",
      "start_time": "2016-12-27T00:00:01Z",
      "reasons_not_servable": [
        "PAUSED_BY_ADVERTISER"
      ],
      "servable": false,
      "daily_budget_amount_local_micro": 3210000,
      "end_time": null,
      "funding_instrument_id": "lygyi",
      "duration_in_days": null,
      "standard_delivery": true,
      "total_budget_amount_local_micro": 140000000,
      "id": "6s9mp",
      "entity_status": "PAUSED",
      "paused": true,
      "account_id": "18ce54d4x5t",
      "frequency_cap": null,
      "currency": "USD",
      "created_at": "2016-12-27T00:00:01Z",
      "updated_at": "2016-12-27T00:00:01Z",
      "deleted": false
    }
  ],
  "data_type": "campaign",
  "total_count": 1,
  "next_cursor": null
}

Hope this helps.


#3

Hi,

Thank you for your reply but I was looking for a different solution.

I followed the 3-legged authorization and have stored the access token locally but haven’t been able to understand how to get the account id using that access token. As to what am I supposed to do next?


#4

@SilverPush: What is the result when you make a request to the GET accounts endpoint?