亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 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 關注
  • 263 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號