试图让 Coinbase API 工作

Trying to Get Coinbase API to work

我试图找出我在使用以下代码与 Coinbase API 一起工作时出错的地方。我安装了 Coinbase 依赖项的 Composer。以前我收到一个错误,指出没有安装 Coinbase class,我发现这是因为路径。我不再收到任何错误,但代码没有执行。有人可以帮忙吗?

    <?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>';
    ?>

根据 the Coinbase repository 上的示例,您遇到了命名空间问题。 PHP 找不到配置或客户端 类。

<?php

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;

在您文件的顶部将解决它。之后,阅读http://php.net/manual/en/language.namespaces.basics.php and http://php.net/manual/en/language.namespaces.rationale.php