<p>Short answer: You don't have to create or set that variable.</p>

<p>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: </p>

<pre><code>https://yourwebsite.com/somefile.php?code=e6eb77a55ba5e6c754fb4ea3c1d53ef73b643c6fd443482ce4ed9e5ef407fc3e
</code></pre>

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

CC BY-SA 3.0
2014-02-15T08:42:12.243Z
2014-02-15T08:42:12.243Z
sersun
<p>I am trying to integrate basecoin api with the code given bellow</p>

<pre><code>&lt;?php
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.
$_REDIRECT_URL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

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

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

    // Request tokens
    $tokens = $coinbaseOauth-&gt;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-&gt;getBalance() . '&lt;br&gt;';
        echo $coinbase-&gt;createButton("Alpaca socks", "10.00", "CAD")-&gt;embedHtml;
    } catch (Coinbase_TokensExpiredException $e) {
        $newTokens = $coinbaseOauth-&gt;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 "&lt;a href=\"" . $coinbaseOauth-&gt;createAuthorizeUrl("balance", "buttons") . "\"&gt;Connect with Coinbase&lt;/a&gt;";
}
</code></pre>

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

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

<p>Please advice me what can I get this variable $_GET['code']</p>

<bitcoind><coinbase.com>
what is $_GET['code'] in coinbase api
sudip-fullstack
# what is $_GET['code'] in coinbase api

(Asked by: username_0 on 2013-12-23)

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

```
<?php
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.
$_REDIRECT_URL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

$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']

**Tags:** bitcoind, coinbase.com


---

## 1 answers

### Answer by username_1 on 2014-02-15. Score: 1

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:

```
https://yourwebsite.com/somefile.php?code=e6eb77a55ba5e6c754fb4ea3c1d53ef73b643c6fd443482ce4ed9e5ef407fc3e

```

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


---

