Reputation: 65
I'm trying to figure out where I'm going wrong with the below code to work with the Coinbase API. I have Composer installed with the Coinbase dependency. Previously I was getting an error that the Coinbase class was not installed, which I figured out was because of the path. I no longer get any error but the code is not executing. Can anyone help?
<?php
require_once __DIR__ . '/usr/bin/vendor/autoload.php';
use coinbase\coinbase;
//I've tried to run it both with and without the following 3 lines of code with no difference
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$apiKey = 'XXX';
$apiSecret = 'XXX';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$account = $client->getPrimaryAccount();
echo 'Account name: ' . $account->getName() . '<br>';
echo 'Account currency: ' . $account->getCurrency() . '<br>';
?>
Upvotes: 3
Views: 707
Reputation: 180147
Per the examples on the Coinbase repository, you've got a namespacing issue. PHP can't find the Configuration or Client classes.
<?php
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
at the top of your file will resolve it. After that, read http://php.net/manual/en/language.namespaces.basics.php and http://php.net/manual/en/language.namespaces.rationale.php.
Upvotes: 2