来自 Yandex.Direct 的 GET 请求为空
Null in GET request from Yandex.Direct
我正在尝试使用 Yandex.Direct API (https://api.direct.yandex.com/json/v5/reports) 获取报告数据,但出现以下错误:
Trying to get property 'result' of non-object
我的参数:
$params = array(
'SelectionCriteria' => array(
'DateFrom' => $startDate,
'DateTo' => $endDate,
'Filter' => array(array(
'Field' => 'CampaignId',
'Operator' => 'EQUALS',
'Values' => array($campaign->getId())
))
),
'FieldNames' => array('Date', 'CriterionId'),
'ReportName' => 'Yandex actual report',
'ReportType' => 'CUSTOM_REPORT',
'DateRangeType' => 'CUSTOM_DATE',
'Format' => 'TSV',
'IncludeDiscount' => 'YES',
'IncludeVAT' => 'NO'
);
然后我将这个数组传递给下一个方法:
$data = $this->client->call("https://api.direct.yandex.com/json/v5/reports", "get", $params);
函数本身:
public function call($url, $method, $params, $headers = []){
$client = new \GuzzleHttp\Client();
$query = [
'method' => $method,
'params' => $params
];
$defHeaders = array_merge([
'Content-type' => 'application/json; charset=utf-8',
'Authorization'=> "Bearer ".$this->token,
],$headers);
$res = $client->request('POST', $url, [
'json' => $query,
'headers' => $defHeaders
]);
$res = json_decode($res->getBody()->getContents());
if(isset($res->error)){
throw new YdException($res->error->error_string, $res->error->error_code, $res->error->error_detail);
}
return $res->result;
}
当我 var_dump($res) 时,我得到 NULL 值。那我做错了什么?
报告以 TSV 格式返回,而不是 JSON。所以才会出现这个问题。
我正在尝试使用 Yandex.Direct API (https://api.direct.yandex.com/json/v5/reports) 获取报告数据,但出现以下错误:
Trying to get property 'result' of non-object
我的参数:
$params = array(
'SelectionCriteria' => array(
'DateFrom' => $startDate,
'DateTo' => $endDate,
'Filter' => array(array(
'Field' => 'CampaignId',
'Operator' => 'EQUALS',
'Values' => array($campaign->getId())
))
),
'FieldNames' => array('Date', 'CriterionId'),
'ReportName' => 'Yandex actual report',
'ReportType' => 'CUSTOM_REPORT',
'DateRangeType' => 'CUSTOM_DATE',
'Format' => 'TSV',
'IncludeDiscount' => 'YES',
'IncludeVAT' => 'NO'
);
然后我将这个数组传递给下一个方法:
$data = $this->client->call("https://api.direct.yandex.com/json/v5/reports", "get", $params);
函数本身:
public function call($url, $method, $params, $headers = []){
$client = new \GuzzleHttp\Client();
$query = [
'method' => $method,
'params' => $params
];
$defHeaders = array_merge([
'Content-type' => 'application/json; charset=utf-8',
'Authorization'=> "Bearer ".$this->token,
],$headers);
$res = $client->request('POST', $url, [
'json' => $query,
'headers' => $defHeaders
]);
$res = json_decode($res->getBody()->getContents());
if(isset($res->error)){
throw new YdException($res->error->error_string, $res->error->error_code, $res->error->error_detail);
}
return $res->result;
}
当我 var_dump($res) 时,我得到 NULL 值。那我做错了什么?
报告以 TSV 格式返回,而不是 JSON。所以才会出现这个问题。