0

Flickr SOAP APIのリクエストを作成しようとしていますが、正しい形式を取得できません。送信したいXMLは次のとおりです。

    <s:Envelope
    xmlns:s="http://www.w3.org/2003/05/soap-envelope"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
    <s:Body>
        <x:FlickrRequest xmlns:x="urn:flickr">
            <method>flickr.test.echo</method>
            <name>value</name>
        </x:FlickrRequest>
    </s:Body>
</s:Envelope>

これが私のコードです:

<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$opts = array('location' => 'http://api.flickr.com/services/soap/',
              'uri'      => 'urn:flickr',
              'trace'    => 1
);
$client = new SOAPClient(null, $opts);
?>

    <?php
      try {

        $data = $client->__soapCall('flickr.test.echo', array('name'));
        print_r($data);

      } catch (SoapFault $exception) {

        echo 'Exception Thrown: '.$exception->faultstring.'<br><br>';  

      print "<pre>\n";
      print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
      print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
      print "</pre>";   

      }

    ?>

応答は次のとおりです。

Exception Thrown: 

Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="urn:flickr" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:flickr.test.echo>
<param0 xsi:type="xsd:string">name</param0>
</ns1:flickr.test.echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="utf-8" ?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
    <s:Body>
        <s:Fault>
            <faultcode>flickr.error.0</faultcode>
            <faultstring>Invalid SOAP envelope.</faultstring>
            <faultactor>http://www.flickr.com/services/soap/</faultactor>
            <details>Please see http://www.flickr.com/services/api/ for more details</details>
        </s:Fault>
    </s:Body>
</s:Envelope>

残念ながら、FlickrはWSDLファイルを提供していません。

ありがとう

<< **更新** >>近づいています。私は自分のコードを変更しました、そしてそれはそれが本来あるべき場所にほとんどあります:

<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

$opts = array('location' => 'http://api.flickr.com/services/soap/',
              'uri'      => 'http://api.flickr.com/services/soap/',
              'trace'    => 1
);
$client = new SOAPClient(null, $opts);
?>
<?php
  try {

    $data = $client->__soapCall("FlickrRequest",
       array(new SoapParam('flickr.test.echo', 'method'), new SoapParam('value', 'name')),
       array('soapaction' => 'http://api.flickr.com/services/soap/')
    );  
    print_r($data);


  } catch (SoapFault $exception) {

    echo 'Exception Thrown:  '.$exception->faultstring.'<br><br>';  

  print "<pre>\n";
  print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
  print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
  print "</pre>";   
  }

?>

現在送信されているものは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.flickr.com/services/soap/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:FlickrRequest>
<method xsi:type="xsd:string">flickr.test.echo</method>
<name xsi:type="xsd:string">value</name>
</ns1:FlickrRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
4

1 に答える 1

0

私はこのコードを使用してそれを機能させることができました:

<?php 
    $url = 'https://api.flickr.com/services/soap';

    $xml_post_string = '<s:Envelope
                            xmlns:s="http://www.w3.org/2003/05/soap-envelope"
                            xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
                            xmlns:xsd="http://www.w3.org/1999/XMLSchema"
                        >
                            <s:Body>
                                <x:FlickrRequest xmlns:x="urn:flickr">
                                    <method>flickr.photos.getRecent</method>
                                    <api_key>YOUR_API_KEY</api_key>
                                    <page>1</page>
                                    <per_page>10</per_page>
                                </x:FlickrRequest>
                            </s:Body>
                        </s:Envelope>';

       $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "Content-length: ".strlen($xml_post_string),
                );

        // PHP cURL
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $response = curl_exec($ch);
        curl_close($ch);
?>

私が呼び出すメソッドはflickr.photos.getRecentで、渡されるパラメーターは次のとおりです。

  • api_key --> ツアー API キー
  • ページ--> 対象のページ
  • per_page --> ページあたりの要素数

応答は次のとおりです。

    <s:envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
    <s:body>
    <x:flickrresponse xmlns:x="urn:flickr">
&lt;photos page="1" pages="100" perpage="10" total="1000"&gt;
    &lt;photo id="14569264388" owner="14957549@N05" secret="6edf4e63b7" server="2924" farm="3" title="Halona Blow Hole.  #hawaii #oahu #halonablowhole #honolulu #beautifulscenery #southshore" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14569264418" owner="107442773@N05" secret="5260e4a304" server="3877" farm="4" title="Chic Planner’s selection of flowers is rich and varied. The arrangements, which were also personally selected by Mr.Suriya Krutthong Creative Director of Chic Planner's, are desinged of contemporary and exude a sense of timeless elegance.  #Floral #ChicPl" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14569463647" owner="88628573@N00" secret="9499a95683" server="2897" farm="3" title="DSC01138.JPG" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14569464207" owner="13792595@N04" secret="6a3ef91dc1" server="3902" farm="4" title="2014-07-25 16.59.40" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14569464337" owner="84797770@N05" secret="5749d84b11" server="2930" farm="3" title="PICT0340.JPG" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14732900256" owner="112321297@N06" secret="a42fc5a063" server="3904" farm="4" title="005" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14753554624" owner="126377022@N07" secret="daf6c95548" server="3900" farm="4" title="Image from page 36 of &amp;quot;Illustrated catalogue and price list of bells, electric gas burners, batteries, push buttons ...&amp;quot; (1899)" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14775778843" owner="34395619@N04" secret="b5f2702bec" server="5585" farm="6" title="_MG_7248.jpg" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14775779293" owner="67793058@N00" secret="447ebe21d3" server="2900" farm="3" title="IMG_1722" ispublic="1" isfriend="0" isfamily="0" /&gt;
    &lt;photo id="14775779583" owner="124068747@N04" secret="38fd7024d8" server="3860" farm="4" title="P7270139" ispublic="1" isfriend="0" isfamily="0" /&gt;
&lt;/photos&gt;
        </x:flickrresponse>
    </s:body>
</s:envelope>
于 2014-07-27T10:18:35.030 に答える