这是数组数据:
Coinbase\Wallet\Resource\ResourceCollection Object
(
[previousUri:Coinbase\Wallet\Resource\ResourceCollection:private] =>
[nextUri:Coinbase\Wallet\Resource\ResourceCollection:private] => /v2/accounts/REMOVED/transactions?starting_after=REMOVED
[resources:Coinbase\Wallet\Resource\ResourceCollection:private] => Array
(
[0] => Coinbase\Wallet\Resource\Transaction Object
(
[type:Coinbase\Wallet\Resource\Transaction:private] => send
[status:Coinbase\Wallet\Resource\Transaction:private] => completed
[amount:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Value\Money Object
(
[amount:Coinbase\Wallet\Value\Money:private] => -0.00016600
[currency:Coinbase\Wallet\Value\Money:private] => BTC
)
[nativeAmount:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Value\Money Object
(
[amount:Coinbase\Wallet\Value\Money:private] => -0.07
[currency:Coinbase\Wallet\Value\Money:private] => USD
)
[description:Coinbase\Wallet\Resource\Transaction:private] => Your first bitcoin!
[fee:Coinbase\Wallet\Resource\Transaction:private] =>
[instantExchange:Coinbase\Wallet\Resource\Transaction:private] =>
[createdAt:Coinbase\Wallet\Resource\Transaction:private] => DateTime Object
(
[date] => 2016-05-18 21:04:04.000000
[timezone_type] => 2
[timezone] => Z
)
[updatedAt:Coinbase\Wallet\Resource\Transaction:private] => DateTime Object
(
[date] => 2016-05-18 21:16:50.000000
[timezone_type] => 2
[timezone] => Z
)
[network:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Value\Network Object
(
[status:Coinbase\Wallet\Value\Network:private] => confirmed
[hash:Coinbase\Wallet\Value\Network:private] => REMOVED
)
[to:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Resource\BitcoinAddress Object
(
[address:Coinbase\Wallet\Resource\BitcoinAddress:private] => 1BJcYDCMHJ3FAqj8YKbcnNq5xxHcxViD5s
[id:Coinbase\Wallet\Resource\Resource:private] =>
[resource:Coinbase\Wallet\Resource\Resource:private] => bitcoin_address
[resourcePath:Coinbase\Wallet\Resource\Resource:private] =>
[rawData:Coinbase\Wallet\Resource\Resource:private] =>
)
[from:Coinbase\Wallet\Resource\Transaction:private] =>
[address:Coinbase\Wallet\Resource\Transaction:private] =>
[application:Coinbase\Wallet\Resource\Transaction:private] =>
[buy:Coinbase\Wallet\Resource\Transaction:private] =>
[sell:Coinbase\Wallet\Resource\Transaction:private] =>
[id:Coinbase\Wallet\Resource\Resource:private] => REMOVED
[resource:Coinbase\Wallet\Resource\Resource:private] => transaction
[resourcePath:Coinbase\Wallet\Resource\Resource:private] => /v2/accounts/REMOVED/transactions/REMOVED
[rawData:Coinbase\Wallet\Resource\Resource:private] => Array
(
[id] => REMOVED
[type] => send
[status] => completed
[amount] => Array
(
[amount] => -0.00016600
[currency] => BTC
)
[native_amount] => Array
(
[amount] => -0.07
[currency] => USD
)
[description] => Your first bitcoin!
[created_at] => 2016-05-18T21:04:04Z
[updated_at] => 2016-05-18T21:16:50Z
[resource] => transaction
[resource_path] => /v2/accounts/REMOVED/transactions/REMOVED
[instant_exchange] =>
[network] => Array
(
[status] => confirmed
[hash] => REMOVED
)
[to] => Array
(
[resource] => bitcoin_address
[address] => 1BJcYDCMHJ3FAqj8YKbcnNq5xxHcxViD5s
)
[details] => Array
(
[title] => Sent bitcoin
[subtitle] => to Bitcoin address
)
)
)
[1] => Coinbase\Wallet\Resource\Transaction Object
(
[type:Coinbase\Wallet\Resource\Transaction:private] => send
[status:Coinbase\Wallet\Resource\Transaction:private] => completed
[amount:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Value\Money Object
(
[amount:Coinbase\Wallet\Value\Money:private] => -0.00016600
[currency:Coinbase\Wallet\Value\Money:private] => BTC
)
[nativeAmount:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Value\Money Object
(
[amount:Coinbase\Wallet\Value\Money:private] => -0.07
[currency:Coinbase\Wallet\Value\Money:private] => USD
)
[description:Coinbase\Wallet\Resource\Transaction:private] => Your first bitcoin!
[fee:Coinbase\Wallet\Resource\Transaction:private] =>
[instantExchange:Coinbase\Wallet\Resource\Transaction:private] =>
[createdAt:Coinbase\Wallet\Resource\Transaction:private] => DateTime Object
(
[date] => 2016-05-18 20:41:29.000000
[timezone_type] => 2
[timezone] => Z
)
[updatedAt:Coinbase\Wallet\Resource\Transaction:private] => DateTime Object
(
[date] => 2016-05-18 20:45:51.000000
[timezone_type] => 2
[timezone] => Z
)
[network:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Value\Network Object
(
[status:Coinbase\Wallet\Value\Network:private] => confirmed
[hash:Coinbase\Wallet\Value\Network:private] => REMOVED
)
[to:Coinbase\Wallet\Resource\Transaction:private] => Coinbase\Wallet\Resource\BitcoinAddress Object
(
[address:Coinbase\Wallet\Resource\BitcoinAddress:private] => 1BJcYDCMHJ3FAqj8YKbcnNq5xxHcxViD5s
[id:Coinbase\Wallet\Resource\Resource:private] =>
[resource:Coinbase\Wallet\Resource\Resource:private] => bitcoin_address
[resourcePath:Coinbase\Wallet\Resource\Resource:private] =>
[rawData:Coinbase\Wallet\Resource\Resource:private] =>
)
[from:Coinbase\Wallet\Resource\Transaction:private] =>
[address:Coinbase\Wallet\Resource\Transaction:private] =>
[application:Coinbase\Wallet\Resource\Transaction:private] =>
[buy:Coinbase\Wallet\Resource\Transaction:private] =>
[sell:Coinbase\Wallet\Resource\Transaction:private] =>
[id:Coinbase\Wallet\Resource\Resource:private] => REMOVED
[resource:Coinbase\Wallet\Resource\Resource:private] => transaction
[resourcePath:Coinbase\Wallet\Resource\Resource:private] => /v2/accounts/REMOVED/transactions/REMOVED
[rawData:Coinbase\Wallet\Resource\Resource:private] => Array
(
[id] => REMOVED
[type] => send
[status] => completed
[amount] => Array
(
[amount] => -0.00016600
[currency] => BTC
)
[native_amount] => Array
(
[amount] => -0.07
[currency] => USD
)
[description] => Your first bitcoin!
[created_at] => 2016-05-18T20:41:29Z
[updated_at] => 2016-05-18T20:45:51Z
[resource] => transaction
[resource_path] => /v2/accounts/REMOVED/transactions/REMOVED
[instant_exchange] =>
[network] => Array
(
[status] => confirmed
[hash] => REMOVED
)
[to] => Array
(
[resource] => bitcoin_address
[address] => 1BJcYDCMHJ3FAqj8YKbcnNq5xxHcxViD5s
)
[details] => Array
(
[title] => Sent bitcoin
[subtitle] => to Bitcoin address
)
)
)
我试图弄清楚如何访问其中一些变量。
例如,我该如何实现这一目标:
$bitcoin_address = [address:Coinbase\Wallet\Resource\Address:private];
$type = [type:Coinbase\Wallet\Resource\Transaction:private];
我知道您无法访问私有作用域,但有什么方法可以解决这个问题吗?如果没有更好的方法,我可以抓取数据吗?
感谢。
答案 0 :(得分:2)
是的,访问您的数据的最佳方式是使用decodeLastResponse
函数。
允许提取这些数组中所需的所有数据。
$address = $client->getAccountAddress($account, $addressId);
$transactions = $client->getAddressTransactions($address);
$transactions = $client->decodeLastResponse();
echo var_dump($transactions['data']);
答案 1 :(得分:1)
几乎所有私有属性都有公共getter (允许您访问私有属性的公共方法)。
$bitcoinAddresses = [];
$types = [];
foreach ($resourceCollection->all() as $transaction) {
$bitcoinAddresses[] = $transaction->getTo()->getAddress();
$types[] = $transaction->getType();
}
如果您访问coinbase/coinbase-php repo,则可以在那里看到源代码。您使用所有属性和方法描述了所有类。
答案 2 :(得分:0)
你需要像这样调用函数 decodeLastResponse :
$addresses = $client->getAccountAddresses($account)
$addresses = $client->decodeLastResponse();