I am attempting to use the PHP Coinbase API. I already have an API key and OAuth key. I already set up my web server. Also, I already downloaded the library on GitHub but I still cannot make it work.
Every time I use this code it returns:
string(213) "{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}"
Relevant Code
$post = [
'grant_type' => 'authorization_code',
'code' => 'xxxxxx',
'client_id' => 'xxxxx',
'client_secret' => 'xxxx',
'redirect_uri' => 'https://sample/mybots/blockchain',
];
$ch = curl_init('https://api.coinbase.com/oauth/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response)
The first thing you should be doing is going to an auth endpoint and getting an auth code, after which you send that back and get an access token as the reponse.
Typically, the request should look like this:
Which you can see here https://www.rfc-editor.org/rfc/rfc6749#section-4.1.1
And indeed in Coinbase docs https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating
You have skipped that step and you are trying to begin from step 3 on the coinbase docs!
Make sure that the client is configured correctly on coinbase too. and that the redirect url matches exactly.