Я новая пчела в CoinBase.
Я использую метод getAccounts () для получения всех учетных записей.
$this->client->getAccounts();
Это возвращает объект типа объекта (Coinbase \ Wallet \ Resource \ ResourceCollection)
object(Coinbase\Wallet\Resource\ResourceCollection)[37]
private 'previousUri' => null
private 'nextUri' => null
private 'resources' =>
array (size=1)
0 =>
object(Coinbase\Wallet\Resource\Account)[35]
private 'name' => string 'BTC Wallet' (length=10)
private 'primary' => boolean true
private 'type' => string 'wallet' (length=6)
private 'currency' => string 'BTC' (length=3)
private 'balance' =>
object(Coinbase\Wallet\Value\Money)[43]
...
private 'nativeBalance' =>
object(Coinbase\Wallet\Value\Money)[47]
...
private 'createdAt' =>
object(DateTime)[48]
...
private 'updatedAt' =>
object(DateTime)[49]
...
private 'id' (Coinbase\Wallet\Resource\Resource) => string 'b12d3892-1228-5da1-a779-c5104bcbd749' (length=36)
private 'resource' (Coinbase\Wallet\Resource\Resource) => string 'account' (length=7)
private 'resourcePath' (Coinbase\Wallet\Resource\Resource) => string '/v2/accounts/b12d3892-1228-5da1-a779-c5104bcbd749' (length=49)
private 'rawData' (Coinbase\Wallet\Resource\Resource) =>
array (size=11)
...
Преобразование ответа с использованием (массива) дает недопустимые символы в ответе.
array (size=3)
'�Coinbase\Wallet\Resource\ResourceCollection�previousUri' => null
'�Coinbase\Wallet\Resource\ResourceCollection�nextUri' => null
'�Coinbase\Wallet\Resource\ResourceCollection�resources' =>
array (size=1)
0 =>
object(Coinbase\Wallet\Resource\Account)[35]
private 'name' => string 'BTC Wallet' (length=10)
private 'primary' => boolean true
private 'type' => string 'wallet' (length=6)
private 'currency' => string 'BTC' (length=3)
private 'balance' =>
object(Coinbase\Wallet\Value\Money)[43]
...
private 'nativeBalance' =>
object(Coinbase\Wallet\Value\Money)[47]
...
private 'createdAt' =>
object(DateTime)[48]
...
private 'updatedAt' =>
object(DateTime)[49]
...
private 'id' (Coinbase\Wallet\Resource\Resource) => string 'b12d3892-1228-5da1-a779-c5104bcbd749' (length=36)
private 'resource' (Coinbase\Wallet\Resource\Resource) => string 'account' (length=7)
private 'resourcePath' (Coinbase\Wallet\Resource\Resource) => string '/v2/accounts/b12d3892-1228-5da1-a779-c5104bcbd749' (length=49)
private 'rawData' (Coinbase\Wallet\Resource\Resource) =>
array (size=11)
...
Любая помощь будет оценена.
Anoop
Был в состоянии исправить по следующему коду.
$accountResponse = $this->client->getAccounts();
foreach ($accountResponse->all() as &$account) {
$responseData[] = $account->getRawData();
}
Попробуйте конвертировать так:
$ account = json_decode (json_encode ($ this-> client-> getAccounts ()), true);
ОБНОВИТЬ
$accounts = $this->client->getAccounts();
$resources = $accounts->all();
foreach($resources as $index=>$details) {
$accArr = [];
foreach($details as $key=>$detail) {
$method = 'get'.ucfirst($key).'()';
$accArr[$key] = $detail->{$method};
$accountsContainer[] = $accArr;
}
}
var_dump($accountsContainer);