0

我正在使用coinbase,我正在尝试获取数据,但响应是它甚至无法生成到json或数组,然后生成到json......

代码:

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

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

$accounts = $client->getAccounts();
print_r($accounts); //Here is the response from down. But I dont know how to 
get data from $accounts->data or anything else cause its not clear repsonse.

回应是:

Coinbase\Wallet\Resource\ResourceCollection Object ( [previousUri:Coinbase\Wallet\Resource\ResourceCollection:private] => [nextUri:Coinbase\Wallet\Resource\ResourceCollection:private] => [resources:Coinbase\Wallet\Resource\ResourceCollection:private] => Array ( [0] => Coinbase\Wallet\Resource\Account Object ( [name:Coinbase\Wallet\Resource\Account:private] => LTC Wallet [primary:Coinbase\Wallet\Resource\Account:private] => [type:Coinbase\Wallet\Resource\Account:private] => wallet [currency:Coinbase\Wallet\Resource\Account:private] => LTC [balance:Coinbase\Wallet\Resource\Account:private] => Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 0 [currency:Coinbase\Wallet\Value\Money:private] => LTC ) [nativeBalance:Coinbase\Wallet\Resource\Account:private] => Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 0 [currency:Coinbase\Wallet\Value\Money:private] => EUR ) [createdAt:Coinbase\Wallet\Resource\Account:private] => DateTime Object ( [date] => 2017-11-16 12:00:19.000000 [timezone_type] => 2 [timezone] => Z ) [updatedAt:Coinbase\Wallet\Resource\Account:private] => DateTime Object ( [date] => 2018-01-17 19:10:56.000000 [timezone_type] => 2 [timezone] => Z ) [id:Coinbase\Wallet\Resource\Resource:private] => someID [resource:Coinbase\Wallet\Resource\Resource:private] => account [resourcePath:Coinbase\Wallet\Resource\Resource:private] => /v2/accounts/someID [rawData:Coinbase\Wallet\Resource\Resource:private] => Array ( [id] => someID [name] => LTC Wallet [primary] => [type] => wallet [currency] => LTC [balance] => Array ( [amount] => 1.00496384 [currency] => LTC ) [created_at] => 2017-11-16T12:00:19Z [updated_at] => 2018-01-17T19:10:56Z [resource] => account [resource_path] => /v2/accounts/someID [native_balance] => Array ( [amount] => 162.25 [currency] => EUR ) ) ) [1] => Coinbase\Wallet\Resource\Account Object ( [name:Coinbase\Wallet\Resource\Account:private] => ETH Wallet [primary:Coinbase\Wallet\Resource\Account:private] => [type:Coinbase\Wallet\Resource\Account:private] => wallet [currency:Coinbase\Wallet\Resource\Account:private] => ETH [balance:Coinbase\Wallet\Resource\Account:private] => Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 0 [currency:Coinbase\Wallet\Value\Money:private] => ETH ) [nativeBalance:Coinbase\Wallet\Resource\Account:private] => Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 0[currency:Coinbase\Wallet\Value\Money:private] => EUR ) [createdAt:Coinbase\Wallet\Resource\Account:private] => DateTime Object ( [date] => 2017-11-16 12:00:19.000000 [timezone_type] => 2 [timezone] => Z ) [updatedAt:Coinbase\Wallet\Resource\Account:private] => DateTime Object ( [date] => 2018-01-15 16:50:26.000000 [timezone_type] => 2 [timezone] => Z ) [id:Coinbase\Wallet\Resource\Resource:private] => someID [resource:Coinbase\Wallet\Resource\Resource:private] => account [resourcePath:Coinbase\Wallet\Resource\Resource:private] => /v2/accounts/someID [rawData:Coinbase\Wallet\Resource\Resource:private] => Array ( [id] => someID [name] => ETH Wallet [primary] => [type] => wallet [currency] => ETH [balance] => Array ( [amount] => 1.06493355 [currency] => ETH ) [created_at] => 2017-11-16T12:00:19Z [updated_at] => 2018-01-15T16:50:26Z [resource] => account [resource_path] => /v2/accounts/someID [native_balance] => Array ( [amount] => 942.46 [currency] => EUR ) ) ) [2] => Coinbase\Wallet\Resource\Account Object ( [name:Coinbase\Wallet\Resource\Account:private] => BTC Wallet [primary:Coinbase\Wallet\Resource\Account:private] => 1 [type:Coinbase\Wallet\Resource\Account:private] => wallet [currency:Coinbase\Wallet\Resource\Account:private] => BTC [balance:Coinbase\Wallet\Resource\Account:private] => Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 0 [currency:Coinbase\Wallet\Value\Money:private] => BTC ) [nativeBalance:Coinbase\Wallet\Resource\Account:private] => Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 0 [currency:Coinbase\Wallet\Value\Money:private] => EUR ) [createdAt:Coinbase\Wallet\Resource\Account:private] => DateTime Object ( [date] => 2017-11-16 12:00:19.000000 [timezone_type] => 2 [timezone] => Z ) [updatedAt:Coinbase\Wallet\Resource\Account:private] => DateTime Object ( [date] => 2018-01-19 21:32:51.000000 [timezone_type] => 2 [timezone] => Z ) [id:Coinbase\Wallet\Resource\Resource:private] => someID [resource:Coinbase\Wallet\Resource\Resource:private] => account [resourcePath:Coinbase\Wallet\Resource\Resource:private] => /v2/accounts/someID [rawData:Coinbase\Wallet\Resource\Resource:private] => Array ( [id] => someID [name] => BTC Wallet [primary] => 1 [type] => wallet [currency] => BTC [balance] => Array ( [amount] => 0.10962561 [currency] => BTC ) [created_at] => 2017-11-16T12:00:19Z [updated_at] => 2018-01-19T21:32:51Z [resource] => account [resource_path] => /v2/accounts/someID [native_balance] => Array ( [amount] => 1067.30 [currency] => EUR ) ) ) ) )

我知道它太大了,但我找不到获取每个数据的方法。

$data->data

$data["data"]

$data[0]

没有工作..

4

1 回答 1

1

您可以使用

$data = $client->decodeLastResponse();
print_r($data);

这将返回一个包含您需要的所有数据的数组。

于 2018-01-24T12:02:10.373 回答