I wrote this title hoping to be able to help others with the response(s) to this question.
Im successfully returning an access_token JSON response using the code below but I'm not sure how to extract the access_token from the returned string with PHP.
function getOAuthCreds() { $endpoint = 'https://api.ebay.com/identity/v1/oauth2/token'; $request = "grant_type=client_credentials&scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope"; $session = curl_init($endpoint); curl_setopt($session, CURLOPT_POST, true); curl_setopt($session, CURLOPT_POSTFIELDS, $request); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $headers = [ 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'Authorization: Basic My xxxx-Base64 Encoded Credentials-xxxx' ]; curl_setopt($session, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($session); curl_close($session); return $response; }
Using the code above Im wanting to populate my 'X-EBAY-API-IAF-TOKEN like so: 'X-EBAY-API-IAF-TOKEN: getOAuthCreds() and any help will be greatly appreciated.