PHP 7.3.4
MacOS Sierra 10.12.6
PHPでYahooのスポンサードサーチAPIを使いたいのですが、Yahoo本家のサンプル? 仕様? SOAP? がよくわかっていません。
SOAP初体験なので、PHPのコードが間違っていないかだけでも知りたいです。
とりあえずエラーではない最低限のレスポンスが返ってくることが目標です。
PHPのSOAPライブラリを使って404やら500エラーを返されるので、ダイレクトにYahooのドキュメントにあったXMLを貼り付けて、file_get_contents()してみたのですが、やはり404やら500エラーを返されます。
php
1<?php 2 3$data = <<< EOM 4<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 5 <SOAP-ENV:Header> 6 <RequestHeader xmlns="http://ss.yahooapis.jp/V201901/CampaignExport" xmlns:ns2="http://ss.yahooapis.jp/V201901"> 7 <ns2:license>1111-1111-1111-1111</ns2:license> 8 <ns2:apiAccountId>2222-2222-2222-2222</ns2:apiAccountId> 9 <ns2:apiAccountPassword>password</ns2:apiAccountPassword> 10 </RequestHeader> 11 </SOAP-ENV:Header> 12 <SOAP-ENV:Body> 13 <get xmlns="http://ss.yahooapis.jp/V201901/CampaignExport" xmlns:ns2="http://ss.yahooapis.jp/V201901"> 14 <selector> 15 <accountId>100000001</accountId> 16 <jobIds>1111</jobIds> 17 <jobIds>1112</jobIds> 18 <statuses>SYSTEM_ERROR</statuses> 19 <statuses>COMPLETED</statuses> 20 <statuses>IN_PROGRESS</statuses> 21 <statuses>TIMEOUT</statuses> 22 <paging> 23 <ns2:startIndex>1</ns2:startIndex> 24 <ns2:numberResults>10</ns2:numberResults> 25 </paging> 26 </selector> 27 </get> 28 </SOAP-ENV:Body> 29</SOAP-ENV:Envelope> 30EOM; 31 32$options = array( 33 'http' => array( 34 'method' => 'POST', 35 'header' => 'Content-type: application/soap+xml; charset=UTF-8', 36 'content' => $data 37 ) 38); 39 40$response = file_get_contents('https://sandbox.ss.yahooapis.jp/services/V201901/CampaignExportService?wsdl', false, stream_context_create($options)); 41var_dump($response); 42?>
結果
text
1Warning: file_get_contents(https://sandbox.ss.yahooapis.jp/services/V201901/CampaignExportService?wsdl): failed to open stream: HTTP request failed! HTTP/1.0 500 Server Error in /Users/hoge/Sites/test/index.php on line 42 2bool(false)
公式のドキュメントはこちらです。XMLはここからコピペしているだけです。
license、apiAccountId、apiAccountPasswordには実際に使うsandbox用の値を入れていますが、そこに間違いはありませんでした。
sandboxのURLでないところをsandboxに変えたり、license、apiAccountId、apiAccountPasswordを上のサンプルそのままにしてみたり、いろいろ試したのですがお手上げです。
SOAPに関する知識が乏しく、何か設定が足りないのかな〜と悩んでおります。
Yahooに問い合わせる前に何かヒントだけでも頂けないでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。