I am trying to integrate basecoin api with the code given bellow

require_once(dirname(__FILE__) . '/lib/Coinbase.php');

// Create an application at https://coinbase.com/oauth/applications and set these values accordingly
/*$_CLIENT_ID = "83a481f96bf28ea4bed1ee8bdc49ba4265609efa40d40477c2a57e913c479065";
$_CLIENT_SECRET = "a8dda20b94d09e84e8fefa5e7560133d9c5af9da93ec1d3e79ad0843d2920bbb";
$_CLIENT_ID = "a3564428fb91cd84460d1272b49037581a64d97418663b5edcbc32a5f4f4ae48";
$_CLIENT_SECRET = "1973603dba1e3d335ca34687df9e01c9a591fbc4055738bee30d1fcb283c848b";

// Note: your redirect URL should use HTTPS.

$coinbaseOauth = new Coinbase_OAuth($_CLIENT_ID, $_CLIENT_SECRET, $_REDIRECT_URL);

if(isset($_GET['code'])) {

    // Request tokens
    $tokens = $coinbaseOauth->getTokens($_GET['code']);

    // The user is now authenticated! Access and refresh tokens are in $tokens
    // Store these tokens safely, and use them to make Coinbase API requests in the future.
    // For example:
    $coinbase = new Coinbase($coinbaseOauth, $tokens);

    try {
        echo 'Balance: ' . $coinbase->getBalance() . '<br>';
        echo $coinbase->createButton("Alpaca socks", "10.00", "CAD")->embedHtml;
    } catch (Coinbase_TokensExpiredException $e) {
        $newTokens = $coinbaseOauth->refreshTokens($tokens);
        // Store $newTokens and retry request
} else {

    // Redirect to Coinbase authorization page
    // The provided parameters specify the access your application will have to the
    // user's account; for a full list, see https://coinbase.com/docs/api/overview
    // You can pass as many scopes as you would like
    echo "<a href=\"" . $coinbaseOauth->createAuthorizeUrl("balance", "buttons") . "\">Connect with Coinbase</a>";

But I am not sure what is $_GET['code'], so it is always go to the else part and echo this part

echo "<a href=\"" . $coinbaseOauth->createAuthorizeUrl("balance", "buttons") . "\">Connect with Coinbase</a>";

Please advice me what can I get this variable $_GET['code']


Short answer: You don't have to create or set that variable.

Long answer: When a user clicks the "Connect with Coinbase" link in that example, they will be sent to Coinbase to authorize your app. After that, Coinbase will send the backto your website (at your callback/redirect URL), and that URL will look something like this:


That really long code in the URL is automatically saved as $_GET['code'] by PHP and can be used by the callback page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.