403 forbidden error coinbase api

0 votes

I am using the following code:

<?php

require_once 'vendor/autoload.php';

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Resource\Address;
use Coinbase\Wallet\Resource\Account;

$apiKey = '**********';
$apiSecret = '*************';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);

try {
    $buyPrice = $client->getBuyPrice('BTC-USD');
} catch (Exception $exc) {
    echo '<pre>';
    echo $exc->getTraceAsString();
    echo '<hr/>';
    echo $exc->getMessage();
    echo '</pre>';

}
?>

I get this error:

#0 C:\xampp\htdocs\coinbase\vendor\coinbase\coinbase\src\HttpClient.php(137): Coinbase\Wallet\Exception\HttpException::wrap(Object(GuzzleHttp\Exception\ClientException))
#1 C:\xampp\htdocs\coinbase\vendor\coinbase\coinbase\src\HttpClient.php(121): Coinbase\Wallet\HttpClient->send(Object(GuzzleHttp\Psr7\Request), Array)
#2 C:\xampp\htdocs\coinbase\vendor\coinbase\coinbase\src\HttpClient.php(74): Coinbase\Wallet\HttpClient->request('GET', '/v2/prices/BTC-...', Array)
#3 C:\xampp\htdocs\coinbase\vendor\coinbase\coinbase\src\Client.php(820): Coinbase\Wallet\HttpClient->get('/v2/prices/BTC-...', Array)
#4 C:\xampp\htdocs\coinbase\vendor\coinbase\coinbase\src\Client.php(118): Coinbase\Wallet\Client->getAndMapMoney('/v2/prices/BTC-...', Array)
#5 C:\xampp\htdocs\coinbase\index.php(16): Coinbase\Wallet\Client->getBuyPrice('BTC-USD')
#6 {main}
Client error: `GET https://api.coinbase.com/v2/prices/BTC-USD/buy` resulted in a `403 Forbidden` response:
Aug 28, 2018 in Blockchain by slayer
• 29,170 points
439 views

1 answer to this question.

0 votes

I had a similiar issue connecting this API, but not using the libary.

This code worked for me

        $url = 'https://api.coinbase.com/v2/prices/BTC-EUR/spot';
        $response = wp_remote_get($url, array(
                'timeout' => 120,
                'headers' => array(
                    'CB-VERSION' => '2017-05-19',
                    'Accept' => '*/*',
                    'Accept-Language' => 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4',
                    'Cache-Control' => 'no-cache',
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 OPR/45.0.2552.882'
                )
            )
        );
answered Aug 28, 2018 by digger
• 26,550 points

Related Questions In Blockchain

0 votes
1 answer

Send Payment error in Blockchain API

The following code should help: $address = null; try ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,020 points
240 views
0 votes
1 answer

How to solve Yobit API connection 503 server error?

Try to use "https://www.yobit.net/api/3/info" URL Instead of ...READ MORE

answered Aug 21, 2018 in Blockchain by slayer
• 29,170 points
54 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
3,565 views
0 votes
1 answer

How to get amount of bitcoins in php?

I’ve tried this code and it works: <?php function ...READ MORE

answered Aug 24, 2018 in Blockchain by slayer
• 29,170 points
54 views
0 votes
1 answer

Required parameter missing: account error

You need to swap out the place ...READ MORE

answered Aug 30, 2018 in Blockchain by slayer
• 29,170 points
52 views
0 votes
1 answer

coin.mx : 403 forbidden error on my web request

I was having the same issue and ...READ MORE

answered Sep 11, 2018 in Blockchain by digger
• 26,550 points
38 views
0 votes
1 answer

Coinbase API: Get transaction fees

The Coinbase "fee" is the difference between ...READ MORE

answered Aug 23, 2018 in Blockchain by digger
• 26,550 points
130 views