Amazon MWS API w/ PHP: alternative to getFeedSubmissionResult

冷暖自知 提交于 2019-12-10 10:27:33

问题


I'm having a problem with retrieving the results of a processed feed file using Amazon MWS API with PHP. I'm using the getFeedSubmissionResult class, to be precise. The problem is that when i use the API, as instructed by the documentation, there are no relevant data that is read by the class that i can access (or so it seems). So my question is: how do i retrieve the raw XML file that amazon sends back and store it to a file on my computer?

I've been retracing the code used by MWS and trying to find where they pull in the XML file from amazon and parse it to try and save that into a file with no luck. I'd deeply appreciate it if someone could direct me to a fix to this, and if not, then maybe a work around may be better.

So this is what i've been doing:

I used the getFeedSubmissionResultSample.php provided in the samples of MWS . Supposedly, this should give me the data that tells me how many items were processed and how many processed items were successful. But it doesn't. So I tried to do a print_r of the response variable:

function invokeGetFeedSubmissionResult(MarketplaceWebService_Interface $service,$request)  {
  try {
          $response = $service->getFeedSubmissionResult($request);
          echo "<br />Var dump here: <pre>";
          print_r($response);
            echo ("<pre>Service Response\n");
            echo ("=============================================================================\n");

            echo("        GetFeedSubmissionResultResponse\n");
            if ($response->isSetGetFeedSubmissionResultResult()) {
              $getFeedSubmissionResultResult = $response->getGetFeedSubmissionResultResult(); 
              echo ("            GetFeedSubmissionResult\n");
              if ($getFeedSubmissionResultResult->isSetContentMd5()) {
                echo ("                ContentMd5\n");
                echo ("                " . $getFeedSubmissionResultResult->getContentMd5() . "\n");
              }
            }
            if ($response->isSetResponseMetadata()) { 
                echo("            ResponseMetadata\n");
                $responseMetadata = $response->getResponseMetadata();
                if ($responseMetadata->isSetRequestId()) 
                {
                    echo("                RequestId\n");
                    echo("                    " . $responseMetadata->getRequestId() . "\n");
                }
            } 

            echo("            ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
 } catch (MarketplaceWebService_Exception $ex) {
     echo("Caught Exception: " . $ex->getMessage() . "\n");
     echo("Response Status Code: " . $ex->getStatusCode() . "\n");
     echo("Error Code: " . $ex->getErrorCode() . "\n");
     echo("Error Type: " . $ex->getErrorType() . "\n");
     echo("Request ID: " . $ex->getRequestId() . "\n");
     echo("XML: " . $ex->getXML() . "\n");
     echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
 }
}

And the output gives me this:

Service Response

    GetFeedSubmissionResultResponse
        GetFeedSubmissionResult
            ContentMd5
            G5Sw+2ooONEZU1iQoqdEOQ==
        ResponseMetadata
            RequestId
                f9d4be45-6710-42eb-850e-f437224f9938
        ResponseHeaderMetadata: RequestId: f9d4be45-6710-42eb-850e-f437224f9938, ResponseContext: EM/RH7RHQhLSc47Tj2a2Uv2CGKEfvxaKOijjcaKeoh8dGISci3yqo9OHZs7dpLDIszJVz4Jt4z8=,9SYUaktMzcOG6UyuyhXu/kJPl0gpLeenslL2rkugDLhDYftMleRx1XIexbVWNxuYl7cO6901Foiv Kp7hvaLeAQ==, Timestamp: 2013-06-18T07:29:37.393Z

I have omitted the var_dump results because i don't know if that may pose a security issue on my part. But in any case, the var_dump didn't give any data that i could access. I have also traced the code to where the classes and their methods to see if i can access it from there but came out empty-handed.

Note that I have the proper parameters for calling in the results (i.e. the FeedSubmissionId) because I've done this with the amazon scratch pad.

Your help would be greatly appreciated! :)

regards, Caleb


回答1:


I had the same problem. The issue is that the response returns the result for you to compare the received file against to verify no corruption during transmission. To get xml response with Message you should save it to file not to php://memory. So the next code works for me fine

$filename = __DIR__.'/file.xml';
$handle = fopen($filename, 'w+');
$request = new MarketplaceWebService_Model_GetFeedSubmissionResultRequest();
$request->setMerchant(MERCHANT_ID);
$request->setFeedSubmissionId(ID_TO_CHANGE);
$request->setFeedSubmissionResult($handle);


try {
    $response = $service->getFeedSubmissionResult($request);
    fclose($handle);

    echo ("Service Response\n");
    echo ("=============================================================================\n");

    echo("        GetFeedSubmissionResultResponse\n");
    if ($response->isSetGetFeedSubmissionResultResult()) {
        $getFeedSubmissionResultResult = $response->getGetFeedSubmissionResultResult();
        echo ("            GetFeedSubmissionResult");

        if ($getFeedSubmissionResultResult->isSetContentMd5()) {
            echo ("                ContentMd5");
            echo ("                " . $getFeedSubmissionResultResult->getContentMd5() . "\n");
        }
    }
    if ($response->isSetResponseMetadata()) {
        echo("            ResponseMetadata\n");
        $responseMetadata = $response->getResponseMetadata();
        if ($responseMetadata->isSetRequestId())
        {
            echo("                RequestId\n");
            echo("                    " . $responseMetadata->getRequestId() . "\n");
        }
    }

    echo("            ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
    echo("Caught Exception: " . $ex->getMessage() . "\n");
    echo("Response Status Code: " . $ex->getStatusCode() . "\n");
    echo("Error Code: " . $ex->getErrorCode() . "\n");
    echo("Error Type: " . $ex->getErrorType() . "\n");
    echo("Request ID: " . $ex->getRequestId() . "\n");
    echo("XML: " . $ex->getXML() . "\n");
    echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}

the result you can find in ./file.xml file this helped me




回答2:


If you do not want to use a file. Then at the end of your try statement.
$xml = stream_get_contents($request->getFeedSubmissionResult());

That will put the xml data into $xml



来源:https://stackoverflow.com/questions/17163536/amazon-mws-api-w-php-alternative-to-getfeedsubmissionresult

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!