question

landem-0 avatar image
0 Likes"
landem-0 asked

OAuth token not working for Shopping. After gotten the application access token, it still cannot work when calling ebay shopping api.

After gotten the Application access token.The code works very well. Below is the code<br />
<?php<br />

$clientID = '<App ID code here>';<br />
$clientSecret = '<App client certification code here>';<br />
$ruName = '<ruName code here>';<br />
$authCode = 'https://signin.ebay.com/ws/eBayISAPI.dll?<br />ThirdPartyAuthSucessFailure&isAuthSuccessue&code=v%5E1.1%2E23I%5E3%23t%5EUl41Xzk6Qjk1N<br />zY3QkRFRUIzMDRFQTBFRUZGNTREMjlGOTE2NUFfMl8xI0VeMjYw&expires_in=299';<br />

$url = 'https://api.ebay.com/identity/v1/oauth2/token';<br />

$headers = [<br />
    'Content-Type: application/x-www-form-urlencoded',<br />
    'Authorization: Basic '.base64_encode($clientID.':'.$clientSecret)<br />
];<br />

$body = http_build_query([<br />
    'grant_type'   => 'client_credentials',<br />
    'code'         => $authCode,
'scope'         => 'https://api.ebay.com/oauth/api_scope',<br />
    'redirect_uri' => $ruName<br />
]);<br />

$curl = curl_init();<br />

curl_setopt_array($curl, array(<br />
    CURLOPT_URL            => $url,<br />
    CURLOPT_RETURNTRANSFER => true,<br />
    CURLOPT_CUSTOMREQUEST  => 'POST',<br />
    CURLOPT_POSTFIELDS     => $body,<br />
    CURLOPT_HTTPHEADER     => $headers<br />
));<br />

$response = curl_exec($curl);<br />
$json = json_decode($response, true);<br />
$err = curl_error($curl);<br />

curl_close($curl);<br />

if ($err) {<br />
    echo "cURL Error #:" . $err;<br />
} else {<br />

     $access_token = $json["access_token"];<br />
  $expires_in = $json["expires_in"];<br />
   $token_type = $json["token_type"];<br />
 echo $access_token.'<br>';<br />
  echo $token_type.'<br>';<br />
    //echo $response."\n";<br />
}<br />

?>
<br />

i got the access token which is the Application access token very well.<br />
But now the biggest problem is, i am trying to use the above (Application access token) to call <br />ebay shopping api in GetMultipleItems but it not working.<br />
i want to use the above Application access token ($access_token) to call the ebay shopping api but<br /> not workng.<br />
Below is the code that i called the ebay shopping api to get GetMultipleItems.   <br />

$headers = array<br />
(<br />
    //'X-EBAY-API-APP-ID: ' . $appid,<br />
'X-EBAY-API-IAF-TOKEN: '.$access_token,<br />
'X-EBAY-API-CALL-NAME:GetMultipleItems',<br />
'X-EBAY-API-SITEID:3',<br />
    'X-EBAY-API-VERSION: 963',<br />
'X-EBAY-API-COMPATIBILITY-LEVEL: 963',<br />
    'X-EBAY-API-REQUEST-ENCODING: XML',<br />
    'Content-Type: text/xml'<br />
);<br />
 
// Generate XML request<br />

echo $headers;

$xml_request ='<?xml version="1.0" encoding="UTF-8"?>
<GetMultipleItemsRequest xmlns="urn:ebay:apis:eBLBaseComponents">

  <itemID>'.$itemId.'</itemID><br />
  <IncludeSelector><br />
      Details,ShippingCosts,ItemSpecifics,Variations<br />
</IncludeSelector><br />
  <paginationInput><br />
      <entriesPerPage>20</entriesPerPage><br />
 </paginationInput><br />
</GetMultipleItemsRequest>';<br />

 $xml_request;<br />
 
// Send request to eBay and load response in $response<br />
$connection = curl_init();<br />
curl_setopt($connection, CURLOPT_URL,"https://open.api.ebay.com/shopping?");<br />
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);<br />
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);<br />
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);<br />
curl_setopt($connection, CURLOPT_POST, 1);<br />
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml_request);<br />
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);<br />
$response = curl_exec($connection);<br />
curl_close($connection);<br />
// Load the call and capture the document returned by eBay API<br />
$resp = simplexml_load_string($response);<br />
 $ack = strtolower( ( string ) $resp->Ack );<br />
if( $ack == 'Success' ) {<br />
    foreach( $resp->Item as $item ) {<br />
        echo "ItemID - " . $item->Title . '<br />';<br />
echo "Item price - " . $item->ConvertedCurrentPrice . '<br />';<br />
        echo "QuantitySold - " . $item->QuantitySold . '<br />';<br />
echo "StoreName - " . $item->StoreName . '<br />';<br />
        echo '<br /><br />';<br />
    }<br />
}else{<br />
return false;<br />
}<br />
?>

This code is not working to get the GetMultipleItems when calling ebay shopping api.
Thanks i will be grateful for any type of help. Thanks in advance.
shopping-apiapplication access tokengetmulitpleitems
· 1
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

whats the error you get ?
0 Likes 0 ·

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.