为了账号安全,请及时绑定邮箱和手机立即绑定

使用 php 下载用户位置性能报告时 bing ads api 响应中的 SoapFault 异常

使用 php 下载用户位置性能报告时 bing ads api 响应中的 SoapFault 异常

PHP
慕桂英546537 2021-12-03 16:17:44
我正在尝试下载 Bing ads 用户位置性能报告。我的 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')    );我也在列数组中包含了所有必需的列。我的刷新令牌和访问令牌已生成,API 正在为身份验证提供正确的响应。为什么它显示错误。谁能帮我 ?
查看完整描述

2 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

请求是空的,即,您没有像 SubmitGenerateReport 期望的那样设置 ReportRequest,例如,它不应该是一个数组。我通过从报告示例助手中注释掉这一行来重现相同的错误:

//$request->ReportRequest = $reportRequest;

GitHub 上有一个示例,创建请求并使用示例助手提交报告请求等。请参阅 ServiceClient 的详细信息(示例用法SDK 类),以帮助映射到您自己的实现。

为了获取所有示例和帮助程序类,我克隆了 Bing Ads SDK 存储库:

git clone https://github.com/BingAds/BingAds-PHP-SDK.git

然后通过 Composer 从示例目录安装 SDK(安装说明位于docs.microsoft.com):

PS C:\dev\github\BingAds-PHP-SDK\samples> composer require microsoft/bingads

No composer.json in current directory, do you want to use the one at C:\dev\github\BingAds-PHP-SDK? [Y,n]? n

Using version v0.12.13.4 for microsoft/bingads

./composer.json has been created

Loading composer repositories with package information

Updating dependencies (including require-dev)

Package operations: 1 install, 0 updates, 0 removals

  - Installing microsoft/bingads (v0.12.13.4): Downloading (100%)

Writing lock file

Generating autoload files

PS C:\dev\github\BingAds-PHP-SDK\samples> php.exe .\v13\ReportRequests.php

You need to provide consent for the application to access your Bing Ads Bing Ads accounts. Copy and paste this authorization endpoint into a web browser and sign in with a Microsoft account with access to a Bing Ads account:


https://login.live-int.com/oauth20_authorize.srf?scope=bingads.manage&prompt=login&client_id=db41b09d-6e50-4f4a-90ac-5a99caefb52f&response_type=code&redirect_uri=https://login.live-int.com/oauth20_desktop.srf


After you have granted consent in the web browser for the application to access your Bing Ads accounts, please enter the response URI that includes the authorization 'code' parameter:

将每个 OAuth 同意指令的结果粘贴到上面的脚本中,然后 ReportRequests.php 应该继续执行,即提交报告请求。


这是 $reportRequest 的 var_dump:


object(SoapVar)#79 (4) {

  ["enc_type"]=>

  int(301)

  ["enc_value"]=>

  object(Microsoft\BingAds\V13\Reporting\AccountPerformanceReportRequest)#35 (11) {

    ["Aggregation"]=>

    string(6) "Weekly"

    ["Columns"]=>

    array(9) {

      [0]=>

      string(10) "TimePeriod"

      [1]=>

      string(9) "AccountId"

      [2]=>

      string(11) "AccountName"

      [3]=>

      string(6) "Clicks"

      [4]=>

      string(11) "Impressions"

      [5]=>

      string(3) "Ctr"

      [6]=>

      string(10) "AverageCpc"

      [7]=>

      string(5) "Spend"

      [8]=>

      string(8) "DeviceOS"

    }

    ["Filter"]=>

    NULL

    ["Scope"]=>

    object(Microsoft\BingAds\V13\Reporting\AccountReportScope)#77 (1) {

      ["AccountIds"]=>

      array(1) {

        [0]=>

        int(MyAccountIdWasHere)

      }

    }

    ["Time"]=>

    object(Microsoft\BingAds\V13\Reporting\ReportTime)#80 (4) {

      ["CustomDateRangeEnd"]=>

      NULL

      ["CustomDateRangeStart"]=>

      NULL

      ["PredefinedTime"]=>

      string(9) "Yesterday"

      ["ReportTimeZone"]=>

      NULL

    }

    ["ExcludeColumnHeaders"]=>

    NULL

    ["ExcludeReportFooter"]=>

    NULL

    ["ExcludeReportHeader"]=>

    NULL

    ["Format"]=>

    string(3) "Tsv"

    ["ReportName"]=>

    string(29) "My Account Performance Report"

    ["ReturnOnlyCompleteData"]=>

    bool(false)

  }

  ["enc_stype"]=>

  string(31) "AccountPerformanceReportRequest"

  ["enc_ns"]=>

  string(43) "https://bingads.microsoft.com/Reporting/v13"

}

我希望这有帮助!


查看完整回答
反对 回复 2021-12-03
?
斯蒂芬大帝

TA贡献1827条经验 获得超8个赞

是的,之前的答案是正确的 - 请求参数结构不正确。这是我没有 bing sdk 的工作代码的一部分。


    $headers = [

        new SoapHeader(

                'https://bingads.microsoft.com/Reporting/v13',

                'CustomerAccountId',

                ...

            ),

            new SoapHeader(

                'https://bingads.microsoft.com/Reporting/v13',

                'CustomerId',

                ...

            ),

            new SoapHeader(

                'https://bingads.microsoft.com/Reporting/v13',

                'DeveloperToken',

                ...

            ),

            new SoapHeader(

                'https://bingads.microsoft.com/Reporting/v13',

                'AuthenticationToken',

                $this->getToken()

            ),

    ];


    $context = [

        'http' => [

            'header' => "Authorization: Bearer {$this->getOAuthToken()}",

        ],

        'ssl' => [

            'verify_peer' => false,

            'verify_peer_name' => false,

        ],

    ];


    $options = array(

            'stream_context' => stream_context_create($context),

      'trace' => TRUE,

      'exceptions' => TRUE,

      'features' => SOAP_SINGLE_ELEMENT_ARRAYS,

      // Disable keep-alive to avoid 'Process open FD table is full'

      'keep-alive' => FALSE,

      'user_agent' => 'BingAdsSDKPHP ' . '13.0.1 ' . PHP_VERSION,


      /**

       * Map long type to string type. For details, see

       * from_long_xml and to_long_xml callbacks.

       */

      'typemap' => array(

        array(

            'type_ns' => 'http://www.w3.org/2001/XMLSchema',

            'type_name' => 'xs:long',

            'to_xml' => 'to_long_xml',

            'from_xml' => 'from_long_xml'

        ),

      )

    );


    $SoapClient = new SOAPClient(static::WSDL_REPORTING, $options);


    $SoapClient->__setSoapHeaders($headers);


并要求自己


    $request = [

        'ReportRequest' => new SoapVar(

        [

            'Format' => 'Tsv',

            'ReportName' => 'My Account Performance Report',

            'ReturnOnlyCompleteData' => false,

            'Aggregation' => 'Weekly',

            'Scope' => ['AccountIds' => [...]],

            'Time' => ['PredefinedTime' => 'Yesterday'],

            'Columns' => [

                  "TimePeriod",

                  "AccountId",

                  "AccountName",

                  "Clicks",

                  "Impressions",

                  "Ctr",

                  "AverageCpc",

                  "Spend",

                  "DeviceOS"

            ]

        ],

        SOAP_ENC_OBJECT,

        'AccountPerformanceReportRequest',

         "https://bingads.microsoft.com/Reporting/v13"

    )];


    $response = $SoapClient->SubmitGenerateReport($request);


查看完整回答
反对 回复 2021-12-03
  • 2 回答
  • 0 关注
  • 213 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信