铊;博士,您必须安装并运行Composer
之前加入这一行。你的代码的 休息:
require __DIR__ . '/vendor/autoload.php';
Coinbase PHP API使用Composer
来处理它的依赖关系,以便遵循Github上详细介绍的安装过程,以避免头痛。
Composer
读取由Coinbase PHP API作者提供的配置文件,并自动创建一个目录结构,该结构包含所需的所有依赖关系,最重要的是自动载入脚本。 PHP过去是100%自包含的,有很多功能和类已经内置,所以很多PHP编码器(例如我)有一些问题需要切换到更模块化的方法,有些类似于Python风格在Perl星系中有pip
命令或PEAR
,等等,当然还有一些重要的区别。
所以,一定要遵循以下步骤:
1)假设你是在Linux上,您必须安装本地Web服务器,和你的网站的文档根目录是/var/www/newsite
。 2)输入您的文档根目录,下载最新的Coinbase PHP API版本并解压缩/解压缩。我建议去发布版本,而不是克隆版本库。
$
$ cd /var/www/newsite
$
$ tar xzvf coinbase-php-2.5.0.ta.gz
3)现在,你需要下载Composer
。转到它的主页https://getcomposer.org/并点击下载。请按照命令行安装部分中的说明进行操作。
为方便起见,我在此处举报,但可能会更改,请务必查看Composer
的主页。从您的文档根:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"
4)最后一步,运行Composer
并等待他做的工作:
$ php composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 26 installs, 0 updates, 0 removals
- Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
- Installing guzzlehttp/guzzle (6.2.3): Downloading (100%)
- Installing psr/log (1.0.2): Downloading (100%)
- Installing symfony/yaml (v3.2.8): Downloading (100%)
- Installing sebastian/version (1.0.6): Downloading (100%)
- Installing sebastian/global-state (1.1.1): Downloading (100%)
- Installing sebastian/recursion-context (1.0.5): Downloading (100%)
- Installing sebastian/exporter (1.2.2): Downloading (100%)
- Installing sebastian/environment (1.3.8): Downloading (100%)
- Installing sebastian/diff (1.4.2): Downloading (100%)
- Installing sebastian/comparator (1.2.4): Downloading (100%)
- Installing doctrine/instantiator (1.0.5): Downloading (100%)
- Installing phpunit/php-text-template (1.2.1): Downloading (100%)
- Installing phpunit/phpunit-mock-objects (2.3.8): Downloading (100%)
- Installing phpunit/php-timer (1.0.9): Downloading (100%)
- Installing phpunit/php-file-iterator (1.4.2): Downloading (100%)
- Installing phpunit/php-token-stream (1.4.11): Downloading (100%)
- Installing phpunit/php-code-coverage (2.2.4): Downloading (100%)
- Installing webmozart/assert (1.2.0): Downloading (100%)
- Installing phpdocumentor/reflection-common (1.0): Downloading (100%)
- Installing phpdocumentor/type-resolver (0.2.1): Downloading (100%)
- Installing phpdocumentor/reflection-docblock (3.1.1): Downloading (100%)
- Installing phpspec/prophecy (v1.7.0): Downloading (100%)
- Installing phpunit/phpunit (4.8.35): Downloading (100%)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files
$
5)考虑到上述的最后一行。Github的Coinbase PHP API自述文件中的例子有点让人误解,因为Composer
很好,并创建了一个名为autoload.php
的文件,它必须用于正确加载新库。
所以,这里是你的代码修改为使用它,从而加载所有所需的依赖:
<?php
require __DIR__ . '/vendor/autoload.php';
$apiKey = 'topsecret';
$apiSecret = 'topkey';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$account = $client->getPrimaryAccount();
行:
require __DIR__ . '/vendor/autoload.php';
应该赚取差价。没有它,脚本退出时屏幕上没有错误,但在php日志文件中有很多错误,但这种行为取决于服务器配置。
希望这会有所帮助!