I know similar questions have already been asked, however, I have tried the solutions without any success. I keep getting this error:
Fatal error: Call to a member function asXML() on a non-object in ... on line 188
Here is my code:
$dom->save("productInfo.xml");
$feedHandle = file_get_contents("productInfo.xml");
$params = array(
'AWSAccessKeyId'=> "*****",
'Action'=>"SubmitFeed",
'SellerId'=> "********",
'SignatureMethod' => "HmacSHA256",
'SignatureVersion'=> "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version' => "2009-01-01",
'FeedContent' => $feedHandle,//must be a string
'FeedType' => "_POST_PRODUCT_DATA_");
// Sort the URL parameters
$url_parts = array();
foreach(array_keys($params) as $key)
$url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key]));
sort($url_parts);
// Construct the string to sign
$url_string = implode("&", $url_parts);
$string_to_sign = "GET\nmws.amazonservices.com\n/Feeds/2009-01-01\n" . $url_string;
// Sign the request
$signature = hash_hmac("sha256", $string_to_sign, "******", TRUE);
// Base64 encode the signature and make it URL safe
$signature = urlencode(base64_encode($signature));
$url = "https://mws.amazonservices.com/Feeds/2009-01-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
$parsed_xml = simplexml_load_string($response);
@fclose($feedHandle);
Header('Content-type: text/xml');
print($parsed_xml->asXML());
I know that $parsed_xml === FALSE
so I know the processing of the XML is not working. I suspect it has something to do with $feedHandle
as I was previously receiving an error that said FeedContent in the array $params
was empty. I know the XML is formatted correctly as I have printed it out and also directly put it in the required field and it worked fine. Also, we used curl-ing in a similar file and it was working fine so I do not think that would be the issue either.