LOCATION and DEVICE ISSUE - Ads API


#1

Hi, When try to fetch the location and devices then getting blank response like below

Response:
stdClass Object
(
[request] => stdClass Object
(
[params] => stdClass Object
(
)
)
[data_type] => job
[next_cursor] =>
[data] => Array
(
)
)

API :
twurl -t -H https://ads-api.twitter.com “/1/stats/jobs/accounts/account-id/?end_time=2017-03-23&entity=CAMPAIGN&entity_ids=7utab&granularity=DAY&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-03-21&platform=DEVICES&segmentation_type=DEVICES”

twurl -t -H https://ads-api.twitter.com “/1/stats/jobs/accounts/account-id/?end_time=2017-03-23&entity=CAMPAIGN&entity_ids=7utab&granularity=DAY&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-03-21&segmentation_type=DEVICES”

And also tried the same for LOCATION but response is same.
So please can you let me know the issue.


#2

@deansharedemo: As our Metrics and Segmentation documentation states, for segmentation_type=DEVICES, the platform param is required.

To get a list of possible platform values, make the following request:

$ twurl -H ads-api.twitter.com "/1/targeting_criteria/platforms"
{
  "data_type": "targeting_criterion",
  "data": [
    {
      "name": "iOS",
      "targeting_type": "PLATFORM",
      "targeting_value": "0"
    },
    {
      "name": "Android",
      "targeting_type": "PLATFORM",
      "targeting_value": "1"
    },
    {
      "name": "BlackBerry phones and tablets",
      "targeting_type": "PLATFORM",
      "targeting_value": "2"
    },
    {
      "name": "Mobile web on other devices",
      "targeting_type": "PLATFORM",
      "targeting_value": "3"
    },
    {
      "name": "Desktop and laptop computers",
      "targeting_type": "PLATFORM",
      "targeting_value": "4"
    }
  ],
  "request": {
    "params": {}
  }
}

Your POST /1/stats/jobs/accounts/:account_id request would then include something like: segmentation_type=DEVICES&platform=0 (for iOS devices).

Hope this helps!


Ads API - Pulling Device, location, etc Info
#3

Hi @juanshishido, Thank you very much for your reply. But information missing about LOCATION. So, please provide the information about location.


#4

@deansharedemo: For locations, you simply make the request with segmentation_type=LOCATIONS. It’s unclear what response you’re seeing. Please provide an example request and response using twurl.


#5

Hi @juanshishido, Please find the required details as you have mentioned.

API : twurl -t -H https://ads-api.twitter.com “/1/stats/jobs/accounts/account-id?end_time=2017-04-25&entity=CAMPAIGN&entity_ids=86onf&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-04-24&segmentation_type=LOCATIONS”

Response :

stdClass Object
    (
        [start_time] => 2017-04-24T00:00:00Z
        [segmentation_type] => LOCATIONS
        [url] => https://ton.twimg.com/advertiser-api-async-analytics/koxGYrZfGtyjjRnfVexrHbMyYxNgKLfSq050BPoaZkCrXzo9VU32XgrUQ3PnL5b8X95jEbjw1ER7J3Y3d35Ut_hE41yUL0fiAJWOJZ8QKZE3HDTqDkjVdwtrodiiakyG.json.gz
        [id_str] => 857927448461103105
        [entity_ids] => Array
            (
                [0] => xxxxx
            )

        [end_time] => 2017-04-25T00:00:00Z
        [country] => 
        [placement] => ALL_ON_TWITTER
        [id] => 8.579274484611E+17
        [expires_at] => 2017-04-30T12:00:19Z
        [account_id] => xxxxxxxxxxx
        [status] => SUCCESS
        [granularity] => TOTAL
        [entity] => CAMPAIGN
        [created_at] => 2017-04-28T12:00:17Z
        [platform] => 
        [updated_at] => 2017-04-28T12:00:19Z
        [metric_groups] => Array
            (
                [0] => ENGAGEMENT
            )

    )

Hope, Details are sufficient for you. There is not showing any information related to location. Please suggest, How can i get the locations?


#6

Thanks for providing these additional details, @deansharedemo.

As our documentation mentions, there are several steps in retrieving the data from an asynchronous analytics job:

  1. Create the job using the POST /1/stats/jobs/accounts/:account_id endpoint
  2. Use the id_str from step 1 in a request to the GET /1/stats/jobs/accounts/:account_id endpoint
  3. Once you see "status": "SUCCESS", download the .gz file from the listed url
  4. gunzip the file to see the results

Your .gz file is here:

https://ton.twimg.com/advertiser-api-async-analytics/koxGYrZfGtyjjRnfVexrHbMyYxNgKLfSq050BPoaZkCrXzo9VU32XgrUQ3PnL5b8X95jEbjw1ER7J3Y3d35Ut_hE41yUL0fiAJWOJZ8QKZE3HDTqDkjVdwtrodiiakyG.json.gz

You should see data for the United Kingdom, Ireland, and the United States.

Hope this helps!


#7

Hi @juanshishido, I am little confuse for below API.

API : twurl -t -H https://ads-api.twitter.com “/1/stats/jobs/accounts/xxxxxxxxxxx?end_time=2017-04-25&entity=CAMPAIGN&entity_ids=86onf&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-04-24&segmentation_type=DEVICES&platform=iOS”

Response :

stdClass Object
(
   [request] => stdClass Object
   (
       [params] => stdClass Object
         (
          )

)

[data_type] => job
[next_cursor] => 
[data] => Array
    (
        [0] => stdClass Object
            (
                [start_time] => 2017-04-24T00:00:00Z
                [segmentation_type] => LOCATIONS
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/koxGYrZfGtyjjRnfVexrHbMyYxNgKLfSq050BPoaZkCrXzo9VU32XgrUQ3PnL5b8X95jEbjw1ER7J3Y3d35Ut_hE41yUL0fiAJWOJZ8QKZE3HDTqDkjVdwtrodiiakyG.json.gz
                [id_str] => 857927448461103105
                [entity_ids] => Array
                    (
                        [0] => 86onf
                    )

                [end_time] => 2017-04-25T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.579274484611E+17
                [expires_at] => 2017-04-30T12:00:19Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-28T12:00:17Z
                [platform] => 
                [updated_at] => 2017-04-28T12:00:19Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [1] => stdClass Object
            (
                [start_time] => 2017-03-21T00:00:00Z
                [segmentation_type] => DEVICES
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/_0zx9wC7Aw6z7yuFQhyBLk_lIl2ZUEnkVzqh4ndn4IFEs1Xffk37eFK28kh1zYaOq8T_011k46PZ-0bnmle1ghDzG-4c42dwMjoYl91yW4Fy8RM-QCdw4obpJFvRsSq7.json.gz
                [id_str] => 857915367875674112
                [entity_ids] => Array
                    (
                        [0] => 7utab
                    )

                [end_time] => 2017-03-23T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5791536787567E+17
                [expires_at] => 2017-04-30T11:12:19Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-28T11:12:17Z
                [platform] => ios
                [updated_at] => 2017-04-28T11:12:19Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [2] => stdClass Object
            (
                [start_time] => 2017-04-24T00:00:00Z
                [segmentation_type] => DEVICES
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/U_ySaz6QF6GHMXDT4vO1-teDWa_aR4A0v5JYasx7Cpif9OvIqJTgYKoxy4Hxpd6K1idN2BOOmGJwqU-UNaPzkETjqAuKYPapGX64pdy4R3-zwfzzeoLqrfyPjgTsxH6B.json.gz
                [id_str] => 857914913779359744
                [entity_ids] => Array
                    (
                        [0] => 86onf
                    )

                [end_time] => 2017-04-25T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5791491377936E+17
                [expires_at] => 2017-04-30T11:10:31Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-28T11:10:29Z
                [platform] => ios
                [updated_at] => 2017-04-28T11:10:31Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [3] => stdClass Object
            (
                [start_time] => 2017-04-24T00:00:00Z
                [segmentation_type] => DEVICES
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/XKdWXP5soLEnZ1CVEieJTVnk3NmZlecIygkkBw-KgZ8bgr4Am6rhZHsKsF0rLRnRN5Pmwnl0Q9jhEwDeV9g4kyMIwOBUJl_k1fnfhzqcdDkKdbxRG-dXbXklZryUTXF8.json.gz
                [id_str] => 857914708883525633
                [entity_ids] => Array
                    (
                        [0] => 86onf
                    )

                [end_time] => 2017-04-25T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5791470888353E+17
                [expires_at] => 2017-04-30T11:09:43Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-28T11:09:40Z
                [platform] => ios
                [updated_at] => 2017-04-28T11:09:43Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [4] => stdClass Object
            (
                [start_time] => 2017-04-24T00:00:00Z
                [segmentation_type] => LOCATIONS
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/96F9XzDisE3T63Emnu_H9vMmO9Fcz9_Nk8JCvVv6LJO6sbG8cL3PkUKwjwITrUgxp_jfMNGHvrDRhWMhm2AT-IitTO0fn7CGZDRUqUJBCzEHQBHoRRzv8r4OP1wSBiFh.json.gz
                [id_str] => 857270225582141440
                [entity_ids] => Array
                    (
                        [0] => 86onf
                    )

                [end_time] => 2017-04-25T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5727022558214E+17
                [expires_at] => 2017-04-28T16:28:45Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-26T16:28:43Z
                [platform] => 
                [updated_at] => 2017-04-26T16:28:45Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [5] => stdClass Object
            (
                [start_time] => 2017-04-24T00:00:00Z
                [segmentation_type] => DEVICES
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/CJ9ZDgPvCGPJOFSJQel9XXSVuPY4JLeOmBuIvx75uugyt6ORZcUYAV1oslE0QUEeOIP7GIM0gFkv-DFVfclcfAXqUzgb1yLRHYICT-8J2JuwsM1a62dg2q3TqYb39-z3.json.gz
                [id_str] => 857268794703609856
                [entity_ids] => Array
                    (
                        [0] => 86onf
                    )

                [end_time] => 2017-04-25T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5726879470361E+17
                [expires_at] => 2017-04-28T16:25:30Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-26T16:23:02Z
                [platform] => ios
                [updated_at] => 2017-04-26T16:25:30Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [6] => stdClass Object
            (
                [start_time] => 2017-03-21T00:00:00Z
                [segmentation_type] => 
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/XBXEQZoLPwazYiVgK2FcHc1COhdI35oFftk6ZdN1yE8WHwkubLPs_2QusfbI1f8hG0rMt2xdyiyz9tg9V5mhTRFR6Ez062TOvArmJvzUuW1Jf8EKyCQGRGE4c--auzJ2.json.gz
                [id_str] => 857261472891719681
                [entity_ids] => Array
                    (
                        [0] => 7utab
                    )

                [end_time] => 2017-03-23T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5726147289172E+17
                [expires_at] => 2017-04-28T15:53:59Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-26T15:53:56Z
                [platform] => 
                [updated_at] => 2017-04-26T15:53:59Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [7] => stdClass Object
            (
                [start_time] => 2017-03-21T00:00:00Z
                [segmentation_type] => 
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/oTzB3vGoHhriLqQhW7rGIEAn2FHU5mQH3tChxBn3eXEmptGrYTtOLJfqTgcki-jGI3uLSlq-usdfC8FrlIAxU8Nqm6T-0w323ZWiDTV4sMzHPDk7k5bt5ktBC9unhVbq.json.gz
                [id_str] => 857261257937874948
                [entity_ids] => Array
                    (
                        [0] => 7utab
                    )

                [end_time] => 2017-03-23T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5726125793787E+17
                [expires_at] => 2017-04-28T15:53:07Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-26T15:53:05Z
                [platform] => 
                [updated_at] => 2017-04-26T15:53:07Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [8] => stdClass Object
            (
                [start_time] => 2017-03-21T00:00:00Z
                [segmentation_type] => 
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/zRzveP63n5bBd1mlkDL-K_5Mwuz7WDkmVSNyoe_pKXy18LfKczNoXxI3T3PzBzWh7NrstNPBX2U-EmWzcBkKs99SAbIaPuIwnmmvLWzm9xld6SfRbMKlzN3UUjlWhzjY.json.gz
                [id_str] => 857260082358362112
                [entity_ids] => Array
                    (
                        [0] => 7utab
                    )

                [end_time] => 2017-03-23T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5726008235836E+17
                [expires_at] => 2017-04-28T15:48:27Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => CAMPAIGN
                [created_at] => 2017-04-26T15:48:25Z
                [platform] => 
                [updated_at] => 2017-04-26T15:48:27Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [9] => stdClass Object
            (
                [start_time] => 2017-03-28T00:00:00Z
                [segmentation_type] => 
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/NZURW7LX5KfFFwrT5OY3Fnc9sk_YUdG01cnF7LXThhpua03LUsn3orq5kx8oEu4qdioI8RqmwGeJRf4YXUJHwyF5_C2P_nZeOVU8SQNnyaAt2gZHpzgNA_dO4EsCtPSD.json.gz
                [id_str] => 857225401420046336
                [entity_ids] => Array
                    (
                        [0] => 89jlk
                    )

                [end_time] => 2017-03-30T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5722540142005E+17
                [expires_at] => 2017-04-28T13:30:38Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => LINE_ITEM
                [created_at] => 2017-04-26T13:30:36Z
                [platform] => 
                [updated_at] => 2017-04-26T13:30:38Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

        [10] => stdClass Object
            (
                [start_time] => 2017-03-28T00:00:00Z
                [segmentation_type] => 
                [url] => https://ton.twimg.com/advertiser-api-async-analytics/EU1PvRINY-jbhRUaHP5g7ynlS3hkFaJWrTdYL1ydtOL4shtvOhq73Ak8vJHqJDCzwrKjTAS54VoRgfNJUrP5sfXYYZ7JstplkHOljmvATHDY6idkcncSIjCAYpuBDRfA.json.gz
                [id_str] => 857225244909592576
                [entity_ids] => Array
                    (
                        [0] => 89jlk
                    )

                [end_time] => 2017-03-30T00:00:00Z
                [country] => 
                [placement] => ALL_ON_TWITTER
                [id] => 8.5722524490959E+17
                [expires_at] => 2017-04-28T13:30:01Z
                [account_id] => xxxxxxxxxxx
                [status] => SUCCESS
                [granularity] => TOTAL
                [entity] => LINE_ITEM
                [created_at] => 2017-04-26T13:29:59Z
                [platform] => 
                [updated_at] => 2017-04-26T13:30:01Z
                [metric_groups] => Array
                    (
                        [0] => ENGAGEMENT
                    )

            )

    )
)

When passing segmentation_type=DEVICES. Yet, segmentation_type=LOCATION is showing in the response.
How segmentation_type=LOCATION is possible in API response by passing segmentation_type=DEVICES?


#8

@deansharedemo: Let’s go through this step-by-step. In this example we’ll request stats for iOS devices.

1. Create the job using the POST /1/stats/jobs/accounts/:account_id endpoint

$ twurl -X POST -H https://ads-api.twitter.com "/1/stats/jobs/accounts/18ce54h6gph?end_time=2017-04-25&entity=CAMPAIGN&entity_ids=86onf&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-04-24&segmentation_type=DEVICES&platform=0"
{
  "request": {
    "params": {
      "start_time": "2017-04-23T23:00:00Z",
      "segmentation_type": "DEVICES",
      "entity_ids": [
        "86onf"
      ],
      "end_time": "2017-04-24T23:00:00Z",
      "placement": "ALL_ON_TWITTER",
      "granularity": "TOTAL",
      "entity": "CAMPAIGN",
      "platform": "0",
      "metric_groups": [
        "ENGAGEMENT"
      ]
    }
  },
  "data_type": "job",
  "data": {
    "start_time": "2017-04-23T23:00:00Z",
    "segmentation_type": "DEVICES",
    "url": null,
    "id_str": "858392488087756801",
    "entity_ids": [
      "86onf"
    ],
    "end_time": "2017-04-24T23:00:00Z",
    "country": null,
    "placement": "ALL_ON_TWITTER",
    "id": 858392488087756801,
    "expires_at": null,
    "account_id": "18ce54h6gph",
    "status": "PROCESSING",
    "granularity": "TOTAL",
    "entity": "CAMPAIGN",
    "created_at": "2017-04-29T18:48:11Z",
    "platform": "0",
    "updated_at": "2017-04-29T18:48:11Z",
    "metric_groups": [
      "ENGAGEMENT"
    ]
  }
}

Note: Notice the use of segmentation_type=DEVICES&platform=0, as stated in my previous post.

2. Use the id_str from step 1 in a request to the GET /1/stats/jobs/accounts/:account_id endpoint

$ twurl -H https://ads-api.twitter.com "/1/stats/jobs/accounts/18ce54h6gph?job_ids=858392488087756801"
{
  "request": {
    "params": {
      "job_ids": [
        858392488087756801
      ]
    }
  },
  "data_type": "job",
  "next_cursor": null,
  "data": [
    {
      "start_time": "2017-04-23T23:00:00Z",
      "segmentation_type": "DEVICES",
      "url": "https://ton.twimg.com/advertiser-api-async-analytics/7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json.gz",
      "id_str": "858392488087756801",
      "entity_ids": [
        "86onf"
      ],
      "end_time": "2017-04-24T23:00:00Z",
      "country": null,
      "placement": "ALL_ON_TWITTER",
      "id": 858392488087756801,
      "expires_at": "2017-05-01T18:48:14Z",
      "account_id": "18ce54h6gph",
      "status": "SUCCESS",
      "granularity": "TOTAL",
      "entity": "CAMPAIGN",
      "created_at": "2017-04-29T18:48:11Z",
      "platform": "0",
      "updated_at": "2017-04-29T18:48:14Z",
      "metric_groups": [
        "ENGAGEMENT"
      ]
    }
  ]
}

3. Once you see "status": "SUCCESS", download the .gz file from the listed url

$ wget https://ton.twimg.com/advertiser-api-async-analytics/7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json.gz
--2017-04-29 11:52:54--  https://ton.twimg.com/advertiser-api-async-analytics/7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json.gz
Resolving ton.twimg.com... 104.244.46.135, 104.244.46.71
Connecting to ton.twimg.com|104.244.46.135|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 676 [application/gzip]
Saving to: '7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json.gz'

7QmZa9Wpf4L34S4Ne301N_O0kufZb 100%[=================================================>]     676  --.-KB/s    in 0s      

2017-04-29 11:52:55 (40.3 MB/s) - '7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json.gz' saved [676/676]

4. gunzip the file to see the results

$ gunzip 7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json.gz

You can either open the .json file or output to the terminal:

$ cat 7QmZa9Wpf4L34S4Ne301N_O0kufZby75bWPfUGE3QochVK4qQArIkGgnlPx7V3tRpzRd3ziyf_tpMadmJacZ3YoHit9MP35xPeF6kJX8q1-js_u4OcmENk4p5nnuebtV.json
{
  "data_type": "stats",
  "time_series_length": 1,
  "data": [
    {
      "id": "86onf",
      "id_data": [
        {
          "segment": {
            "segment_name": "iPad 3",
            "segment_value": "1x"
          },
          "metrics": {
            "impressions": [
              1
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 5C",
            "segment_value": "22"
          },
          "metrics": {
            "impressions": [
              230
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              2
            ],
            "clicks": [
              2
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": [
              1
            ],
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPod Touch",
            "segment_value": "1u"
          },
          "metrics": {
            "impressions": [
              5
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 6S Plus",
            "segment_value": "4r"
          },
          "metrics": {
            "impressions": [
              163
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              3
            ],
            "clicks": [
              3
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 6 Plus",
            "segment_value": "47"
          },
          "metrics": {
            "impressions": [
              114
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 6",
            "segment_value": "46"
          },
          "metrics": {
            "impressions": [
              685
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              3
            ],
            "clicks": [
              3
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": [
              1
            ],
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 5S",
            "segment_value": "21"
          },
          "metrics": {
            "impressions": [
              14
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 6S",
            "segment_value": "4q"
          },
          "metrics": {
            "impressions": [
              733
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              3
            ],
            "clicks": [
              3
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": [
              1
            ],
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 7",
            "segment_value": "5c"
          },
          "metrics": {
            "impressions": [
              445
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              1
            ],
            "clicks": [
              1
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPad mini",
            "segment_value": "1z"
          },
          "metrics": {
            "impressions": [
              2
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPad 2",
            "segment_value": "1w"
          },
          "metrics": {
            "impressions": [
              1
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 7 Plus",
            "segment_value": "5e"
          },
          "metrics": {
            "impressions": [
              213
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 5",
            "segment_value": "1t"
          },
          "metrics": {
            "impressions": [
              50
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              1
            ],
            "clicks": [
              1
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": [
              1
            ],
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 4",
            "segment_value": "1r"
          },
          "metrics": {
            "impressions": [
              3
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPad Air 2",
            "segment_value": "48"
          },
          "metrics": {
            "impressions": [
              1
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "Unknown",
            "segment_value": "0"
          },
          "metrics": {
            "impressions": [
              18
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone 4S",
            "segment_value": "1s"
          },
          "metrics": {
            "impressions": [
              11
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": null,
            "clicks": null,
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "iPhone SE",
            "segment_value": "5h"
          },
          "metrics": {
            "impressions": [
              154
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              3
            ],
            "clicks": [
              3
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        }
      ]
    }
  ],
  "request": {
    "params": {
      "start_time": "2017-04-23T23:00:00Z",
      "segmentation_type": "DEVICES",
      "entity_ids": [
        "86onf"
      ],
      "end_time": "2017-04-24T23:00:00Z",
      "country": null,
      "placement": "ALL_ON_TWITTER",
      "granularity": "TOTAL",
      "entity": "CAMPAIGN",
      "platform": "0",
      "metric_groups": [
        "ENGAGEMENT"
      ]
    }
  }
}

Notice that we do not see anything related to location in the response above.


When making a request with segmentation_type=LOCATION we see the following (after following the same steps as before):

$ twurl -X POST -H https://ads-api.twitter.com "/1/stats/jobs/accounts/18ce54h6gph?end_time=2017-04-25&entity=CAMPAIGN&entity_ids=86onf&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-04-24&segmentation_type=LOCATIONS"
{
  "data_type": "stats",
  "time_series_length": 1,
  "data": [
    {
      "id": "86onf",
      "id_data": [
        {
          "segment": {
            "segment_name": "United States",
            "segment_value": "96683cc9126741d1"
          },
          "metrics": {
            "impressions": [
              474
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              4
            ],
            "clicks": [
              4
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "United Kingdom",
            "segment_value": "6416b8512febefc9"
          },
          "metrics": {
            "impressions": [
              2579
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              20
            ],
            "clicks": [
              20
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": [
              7
            ],
            "carousel_swipes": null
          }
        },
        {
          "segment": {
            "segment_name": "Ireland",
            "segment_value": "ea679934779f45c7"
          },
          "metrics": {
            "impressions": [
              761
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": null,
            "engagements": [
              2
            ],
            "clicks": [
              2
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": [
              1
            ],
            "carousel_swipes": null
          }
        }
      ]
    }
  ],
  "request": {
    "params": {
      "start_time": "2017-04-23T23:00:00Z",
      "segmentation_type": "LOCATIONS",
      "entity_ids": [
        "86onf"
      ],
      "end_time": "2017-04-24T23:00:00Z",
      "country": null,
      "placement": "ALL_ON_TWITTER",
      "granularity": "TOTAL",
      "entity": "CAMPAIGN",
      "platform": null,
      "metric_groups": [
        "ENGAGEMENT"
      ]
    }
  }
}

#9

@deansharedemo: Was the information in my previous post helpful? Did it help clarify?


#10

You always provide the helpful solution. Thank you so much @juanshishido for you support. I appreciate your support.
Thank a lot.


#11

Hi @juanshishido, Facing issue when using devices API.

When running the below API using twurl:

$ twurl -X POST -H https://ads-api.twitter.com "/1/stats/jobs/accounts/xxxxxxxxx?end_time=2017-04-25&entity=CAMPAIGN&entity_ids=86onf&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-04-24&segmentation_type=DEVICES&platform=0"
{  
  "request":{  
    "params":{  
      "start_time":"2017-04-23T23:00:00Z",
      "segmentation_type":"DEVICES",
      "entity_ids":[  
        "xxxxxx"
      ],
      "end_time":"2017-04-24T23:00:00Z",
      "placement":"ALL_ON_TWITTER",
      "granularity":"TOTAL",
      "entity":"CAMPAIGN",
      "platform":"0",
      "metric_groups":[  
        "ENGAGEMENT"
      ]
    }
  },
  "data_type":"job",
  "data":{  
    "start_time":"2017-04-23T23:00:00Z",
    "segmentation_type":"DEVICES",
    "url":null,
    "id_str":"863011265395937280",
    "entity_ids":[  
      "xxxxxxx"
    ],
    "end_time":"2017-04-24T23:00:00Z",
    "country":null,
    "placement":"ALL_ON_TWITTER",
    "id":863011265395937280,
    "expires_at":null,
    "account_id":"xxxxxxxxxx",
    "status":"PROCESSING",
    "granularity":"TOTAL",
    "entity":"CAMPAIGN",
    "created_at":"2017-05-12T12:41:34Z",
    "platform":"0",
    "updated_at":"2017-05-12T12:41:34Z",
    "metric_groups":[  
      "ENGAGEMENT"
    ]
  }
}

It means working fine.

But When I run the below API then in the response, there are showing array of object under data.
API

twurl POST -H https://ads-api.twitter.com "/1/stats/jobs/accounts/xxxxxxxxx?end_time=2017-04-25&entity=CAMPAIGN&entity_ids=86onf&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2017-04-24&segmentation_type=DEVICES&platform=0"
{  
  "request":{  
    "params":{  
      "start_time":"2017-04-23T23:00:00Z",
      "segmentation_type":"DEVICES",
      "entity_ids":[  
        "xxxxxx"
      ],
      "end_time":"2017-04-24T23:00:00Z",
      "placement":"ALL_ON_TWITTER",
      "granularity":"TOTAL",
      "entity":"CAMPAIGN",
      "platform":"0",
      "metric_groups":[  
        "ENGAGEMENT"
      ]
    }
  },
  "data_type":"job",
  "data":{  
    "start_time":"2017-04-23T23:00:00Z",
    "segmentation_type":"DEVICES",
    "url":null,
    "id_str":"863011265395937280",
    "entity_ids":[  
      "xxxxxxx"
    ],
    "end_time":"2017-04-24T23:00:00Z",
    "country":null,
    "placement":"ALL_ON_TWITTER",
    "id":863011265395937280,
    "expires_at":null,
    "account_id":"xxxxxxxxxx",
    "status":"PROCESSING",
    "granularity":"TOTAL",
    "entity":"CAMPAIGN",
    "created_at":"2017-05-12T12:41:34Z",
    "platform":"0",
    "updated_at":"2017-05-12T12:41:34Z",
    "metric_groups":[  
      "ENGAGEMENT"
    ]
  },
  {  
    "start_time":"2017-04-23T23:00:00Z",
    "segmentation_type":"DEVICES",
    "url":null,
    "id_str":"863011265395937280",
    "entity_ids":[  
      "xxxxxxx"
    ],
    "end_time":"2017-04-24T23:00:00Z",
    "country":null,
    "placement":"ALL_ON_TWITTER",
    "id":863011265395937280,
    "expires_at":null,
    "account_id":"xxxxxxxxxx",
    "status":"PROCESSING",
    "granularity":"TOTAL",
    "entity":"CAMPAIGN",
    "created_at":"2017-05-12T12:41:34Z",
    "platform":"0",
    "updated_at":"2017-05-12T12:41:34Z",
    "metric_groups":[  
      "ENGAGEMENT"
    ]
  },
  {  
    "start_time":"2017-04-23T23:00:00Z",
    "segmentation_type":"DEVICES",
    "url":null,
    "id_str":"863011265395937280",
    "entity_ids":[  
      "xxxxxxx"
    ],
    "end_time":"2017-04-24T23:00:00Z",
    "country":null,
    "placement":"ALL_ON_TWITTER",
    "id":863011265395937280,
    "expires_at":null,
    "account_id":"xxxxxxxxxx",
    "status":"PROCESSING",
    "granularity":"TOTAL",
    "entity":"CAMPAIGN",
    "created_at":"2017-05-12T12:41:34Z",
    "platform":"0",
    "updated_at":"2017-05-12T12:41:34Z",
    "metric_groups":[  
      "ENGAGEMENT"
    ]
  }
}

Please let me know what could be the issue. Or if you can suggest some other API for devices data please feel free to let me know.


#12

@deansharedemo: Notice that you’re missing the -X before POST in the second request. This implies you’re making a GET request to this endpoint, which provides the details of all of your asynchronous jobs and is why data is an array. See GET /1/stats/jobs/accounts/:account_id for more information.


#13

Hi @juanshishido, Thank you very much for your reply.

I have checked the link GET /1/stats/jobs/accounts/:account_id but before using the shared API, I would need to create a job.

After short research, I found an API (URL : POST /1/stats/jobs/accounts/:account_id) and it is working with POST method. When I use the API POST /1/stats/jobs/accounts/:account_id then getting below response.
Response :

stdClass Object
(
[errors] => Array
    (
        [0] => stdClass Object
            (
                [code] => UNAUTHORIZED_ACCESS
                [message] => This request is not properly authenticated
            )

    )

[request] => stdClass Object
    (
        [params] => stdClass Object
            (
            )

    )

) 

Now, I would need job_id for using the API GET /1/stats/jobs/accounts/:account_id , So Can you share another API which is working with GET method to get the job_id as job_id providing by the API POST /1/stats/jobs/accounts/:account_id.


#14

Hi @juanshishido, Have you review the above query?


#15

@deansharedemo: It sounds like you’re interested in understanding how the POST and GET endpoints can work together. Please take a look at this post for that information. I’m sure you’ll be able to figure it out.

In addition, it looks like your authentication credentials are missing or incorrect. See this post for more information.


#16

Hi @juanshishido, Is any limitation for calling the endpoint : POST /1/stats/jobs/accounts/:account_id If I call repeatedly with UNAUTHORIZED_ACCESS error for debugging purpose.


#17

Hi @juanshishido, Please don’t reply on just above comment.