我正在尝试下载 Bing 广告用户位置效果报告。
我的 php 代码是:
define("ADCENTER_API_ENDPOINT", "https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13");
define("ADCENTER_API_NAMESPACE", "https://bingads.microsoft.com/Reporting/v13");
define("ADCENTER_API_REPORT_SERVICE", ADCENTER_API_ENDPOINT . "/ReportingService.svc?wsdl");
try {
$headers = array(
new SoapHeader(ADCENTER_API_NAMESPACE, 'DeveloperToken', DEVELOPER_TOKEN, false),
new SoapHeader(ADCENTER_API_NAMESPACE, 'AuthenticationToken', $access_token, false),
new SoapHeader(ADCENTER_API_NAMESPACE, 'CustomerAccountId', CUSTOMER_ACCOUNT_ID, false),
new SoapHeader(ADCENTER_API_NAMESPACE, 'CustomerId', CUSTOMER_ID, false),
new SoapHeader(ADCENTER_API_NAMESPACE, 'Password', USER_PASS, false),
new SoapHeader(ADCENTER_API_NAMESPACE, 'UserName', USER_EMAIL, false)
);
$request = array(
"Format" => 'Csv',
"ReportName" => 'UserLocationPerformanceReport',
"Aggregation" => 'Hourly',
"Columns" => array('CampaignName','CampaignStatus','Country','LocationId','TimePeriod','AccountName','Ctr','Spend','AverageCpc'),
"Scope" => array('AccountIds' => [CUSTOMER_ACCOUNT_ID]),
"Time" => array('PredefinedTime' => 'Today')
);
// Specify the type of report
// $reportType = "AdPerformanceReportRequest";
$reportType = "UserLocationPerformanceReport";
// Create the SOAP client
$client = new SOAPClient(ADCENTER_API_REPORT_SERVICE);
// Encode the request
// $params = array('ReportRequest' => new SoapVar($request, SOAP_ENC_ARRAY, $reportType, ADCENTER_API_NAMESPACE));
$params = array('UserLocationPerformanceReportRequest' => new SoapVar($request, SOAP_ENC_ARRAY, $reportType, ADCENTER_API_NAMESPACE));
// Schedule report
$result = $client->__soapCall("SubmitGenerateReport", array("SubmitGenerateReportRequest" => $params), null, $headers);
// Get the report ID
$reportRequestId = $result->ReportRequestId;
// Wait for the report to complete
$pollDelay = 20;
$params = array('ReportRequestId' => $reportRequestId);
$reportStatus = "Pending";
while ($reportStatus == "Pending") {
sleep($pollDelay);
$result = $client->__soapCall("PollGenerateReport", array('PollGenerateReportRequest' => $params), null, $headers);
$reportStatus = $result->ReportRequestStatus->Status;
}
// Download the report
if ($reportStatus == 'Success') {
$downloadURL = $result->ReportRequestStatus->ReportDownloadUrl;
$filename = CUSTOMER_ACCOUNT_ID.".zip";
file_put_contents($filename, file_get_contents($downloadURL));
} else {
// Error occured
print "Report download failed";
}
} catch (Exception $e) {
print_r($e);
print $client->__getLastRequest() . "\n";
print $client->__getLastResponse() . "\n";
}
我收到了这个回复。
SoapFault Object
(
[message:protected] => Invalid client data. Check the SOAP fault details for more information
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => E:\xampp\htdocs\searchops\crons\bingapicron.php
[line:protected] => 145
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => E:\xampp\htdocs\searchops\crons\bingapicron.php
[line] => 145
[function] => __soapCall
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => SubmitGenerateReport
[1] => Array
(
[SubmitGenerateReportRequest] => Array
(
[UserLocationPerformanceReportRequest] => SoapVar Object
(
[enc_type] => 300
[enc_value] => Array
(
[Format] => Csv
[ReportName] => UserLocationPerformanceReport
[Aggregation] => Hourly
[Columns] => Array
(
[0] => CampaignName
[1] => CampaignStatus
[2] => Country
[3] => LocationId
[4] => TimePeriod
[5] => AccountName
[6] => Ctr
[7] => Spend
[8] => AverageCpc
)
[Scope] => Array
(
[AccountIds] => Array
(
[0] => id_here
)
)
[Time] => Array
(
[PredefinedTime] => Today
)
)
[enc_stype] => UserLocationPerformanceReport
[enc_ns] => https://bingads.microsoft.com/Reporting/v13
)
)
)
[2] =>
[3] => Array
(
[0] => SoapHeader Object
(
[namespace] => https://bingads.microsoft.com/Reporting/v13
[name] => DeveloperToken
[data] => token_here
[mustUnderstand] =>
)
[1] => SoapHeader Object
(
[namespace] => https://bingads.microsoft.com/Reporting/v13
[name] => AuthenticationToken
[data] => auth_token_here
[mustUnderstand] =>
)
[2] => SoapHeader Object
(
[namespace] => https://bingads.microsoft.com/Reporting/v13
[name] => CustomerAccountId
[data] => c_a_id_here
[mustUnderstand] =>
)
[3] => SoapHeader Object
(
[namespace] => https://bingads.microsoft.com/Reporting/v13
[name] => CustomerId
[data] => c_id_here
[mustUnderstand] =>
)
[4] => SoapHeader Object
(
[namespace] => https://bingads.microsoft.com/Reporting/v13
[name] => Password
[data] => pwd_here
[mustUnderstand] =>
)
[5] => SoapHeader Object
(
[namespace] => https://bingads.microsoft.com/Reporting/v13
[name] => UserName
[data] => email_here
[mustUnderstand] =>
)
)
)
)
)
[previous:Exception:private] =>
[faultstring] => Invalid client data. Check the SOAP fault details for more information
[faultcode] => s:Server
[detail] => stdClass Object
(
[ApiFaultDetail] => stdClass Object
(
[TrackingId] => eeb24fc5-9267-4987-9239-d2575cd8d7e6
[BatchErrors] =>
[OperationErrors] => stdClass Object
(
[OperationError] => stdClass Object
(
[Code] => 100
[Details] =>
[ErrorCode] => NullRequest
[Message] => The request message is null.
)
)
)
)
)
我已经在列数组中包含了所有必需的列。生成了我的刷新令牌和访问令牌,并且 api 为身份验证提供了正确的响应。
为什么它显示错误。谁能帮我 ?