Hi, I am trying to get the async job id by using http_method=POST for some line_items.
it works using twurl
twurl -X POST -H ads-api.twitter.com "/2/stats/jobs/accounts/aaglc?entity=LINE_ITEM&granularity=DAY&start_time=2017-07-10T07:00:00Z&end_time=2017-07-14T07:00:00Z&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&segmentation_type=PLATFORMS&entity_ids=2gy2,2gy3,2ljbq,2ljcw,2ljdn,2ljh8,2ljop,2ljrh,7g5ju,7i4ci,7i4x6,7i4zq,7j7el,7j7ex,7j7ff,7n9gq,7n9h4,7n9ia,7n9j5,7pp54" | jq
{
"request": {
"params": {
"start_time": "2017-07-10T07:00:00Z",
"segmentation_type": "PLATFORMS",
"entity_ids": [
"2gy2",
"2gy3",
"2ljbq",
"2ljcw",
"2ljdn",
"2ljh8",
"2ljop",
"2ljrh",
"7g5ju",
"7i4ci",
"7i4x6",
"7i4zq",
"7j7el",
"7j7ex",
"7j7ff",
"7n9gq",
"7n9h4",
"7n9ia",
"7n9j5",
"7pp54"
],
"end_time": "2017-07-14T07:00:00Z",
"placement": "ALL_ON_TWITTER",
"granularity": "DAY",
"entity": "LINE_ITEM",
"metric_groups": [
"ENGAGEMENT"
]
}
},
"data": {
"start_time": "2017-07-10T07:00:00Z",
"segmentation_type": "PLATFORMS",
"url": null,
"id_str": "886737310494085120",
"entity_ids": [
"2gy2",
"2gy3",
"2ljbq",
"2ljcw",
"2ljdn",
"2ljh8",
"2ljop",
"2ljrh",
"7g5ju",
"7i4ci",
"7i4x6",
"7i4zq",
"7j7el",
"7j7ex",
"7j7ff",
"7n9gq",
"7n9h4",
"7n9ia",
"7n9j5",
"7pp54"
],
"end_time": "2017-07-14T07:00:00Z",
"country": null,
"placement": "ALL_ON_TWITTER",
"id": 886737310494085100,
"expires_at": null,
"account_id": "aaglc",
"status": "PROCESSING",
"granularity": "DAY",
"entity": "LINE_ITEM",
"created_at": "2017-07-17T00:00:24Z",
"platform": null,
"updated_at": "2017-07-17T00:00:24Z",
"metric_groups": [
"ENGAGEMENT"
]
}
}
But not works when using request() from script fetch_stats.py in github project ads-platform-tools
stats_url ="https://ads-api.twitter.com/2/stats/jobs/accounts/aaglc?entity=LINE_ITEM&granularity=DAY&start_time=2017-07-10T07:00:00Z&end_time=2017-07-14T07:00:00Z&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&segmentation_type=PLATFORMS&entity_ids=2gy2,2gy3,2ljbq,2ljcw,2ljdn,2ljh8,2ljop,2ljrh,7g5ju,7i4ci,7i4x6,7i4zq,7j7el,7j7ex,7j7ff,7n9gq,7n9h4,7n9ia,7n9j5,7pp54"
headers=None
res_headers, res_data = request(user_twurl, 'POST', headers, stats_url)
print res_headers
print res_data
{
"status": "401",
"x-api-version": "1.0",
"content-length": "122",
"x-xss-protection": "1; mode=block",
"x-content-type-options": "nosniff",
"content-disposition": "attachment; filename=json.json",
"set-cookie": "personalization_id=\"v1_Cs19xW4U7/GwvGPuJHp43Q==\"; Expires=Tue, 16 Jul 2019 23:48:17 UTC; Path=/; Domain=.twitter.com, guest_id=v1%3A150024889767824900; Expires=Tue, 16 Jul 2019 23:48:17 UTC; Path=/; Domain=.twitter.com",
"strict-transport-security": "max-age=631138519",
"x-tsa-request-body-time": "0",
"server": "tsa_a",
"x-connection-hash": "514780e49039ece62db5d7da0fe42b8a",
"x-runtime": "3.2E-5",
"-content-encoding": "gzip",
"date": "Sun, 16 Jul 2017 23:48:17 GMT",
"x-transaction": "004e2193005742b8",
"x-frame-options": "SAMEORIGIN",
"x-response-time": "8",
"content-type": "application/json;charset=utf-8"
}
{
"errors": [
{
"message": "This request is not properly authenticated",
"code": "UNAUTHORIZED_ACCESS"
}
],
"request": {
"params": {}
}
}
But the request() function works for “GET”
stats_url ="https://ads-api.twitter.com/2/stats/accounts/aaglc?entity=LINE_ITEM&granularity=DAY&start_time=2017-07-10T07:00:00Z&end_time=2017-07-14T07:00:00Z&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&segmentation_type=PLATFORMS&entity_ids=2gy2,2gy3,2ljbq,2ljcw,2ljdn,2ljh8,2ljop,2ljrh,7g5ju,7i4ci,7i4x6,7i4zq,7j7el,7j7ex,7j7ff,7n9gq,7n9h4,7n9ia,7n9j5,7pp54"
headers=None
res_headers, res_data = request(user_twurl, 'GET', headers, stats_url)
# I will skip posting the repsonse here
I would like to use the request() to deal with all my requests.
Could anyone help me here?
Thanks