首页 > 解决方案 > 致命错误:未找到接口“Coinbase\Wallet\Authentication\Authentication”

问题描述

我正在尝试创建 PHP API,我已经从 GitHub 下载了 PHP 库并创建了一个 index.php 文件以开始工作,下面是索引代码

<?php
require_once('src/Client.php');
require_once('src/Configuration.php');
require_once('src/Authentication/ApiKeyAuthentication.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;

$apiKey="";
$apiSecret="";

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

?> 

这会产生以下错误

致命错误:在第 8 行的 /home/exhakduz/api/coinbase-php-master/src/Authentication/ApiKeyAuthentication.php 中找不到接口“Coinbase\Wallet\Authentication\Authentication”我找不到任何解决方案

标签: phpcoinbase-api

解决方案


composer改为使用,并composer在您的index.php. 文档建议也安装该库composer

使用 Composer 安装库。如果您不熟悉 Composer 或依赖管理器,请阅读 Composer 文档。

作曲家设置/安装

注意:下面的所有命令都需要从 index.php 所在的同一目录中运行。

  1. 首先,您需要下载并安装 composer。当前可用的版本是1.8.6. 将其下载到与您的脚本phar相同的位置。index.php同时创建一个composer.json文件{}作为内容,composer将你的依赖项保存到这个文件中。

  2. 确保composer.phar具有执行权限(如果在 linux 上运行chmod +x ./composer.phar

  3. 运行./composer.phar require coinbase/coinbase。这应该将依赖项安装在一个vendor目录中。

最后,您可以autoloader composer在安装依赖项时要求生成,您看到的缺失Interface错误将得到解决。

composer.json文件应包含以下内容(最低限度):

{
    "require": {
        "coinbase/coinbase": "^2.8"
    }
}

使用自动加载器的示例

<?php

require_once('vendor/autoload.php');

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

$apiKey="";
$apiSecret="";

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

推荐阅读