Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Catchable fatal error: Object of class stdClass could not be converted to string

Estas en el tema de Catchable fatal error: Object of class stdClass could not be converted to string en el foro de PHP en Foros del Web. Hola phperos! estoy implementando DogeCoin en mi web de juego con bitcoin. He instalado este dogeapi: https://github.com/ummjackson/dogeapi-php En el server esta así: Librería del DogeApi: ...
  #1 (permalink)  
Antiguo 17/05/2014, 07:35
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 6 meses
Puntos: 0
Catchable fatal error: Object of class stdClass could not be converted to string

Hola phperos! estoy implementando DogeCoin en mi web de juego con bitcoin.

He instalado este dogeapi: https://github.com/ummjackson/dogeapi-php

En el server esta así:

Librería del DogeApi: http://dados.coinspain.es/lib/dogeapi.php.php

PHP para la prueba de funcionalidad: http://dados.coinspain.es/lib/testdogeapi.php:

Código:
<?php
require_once 'dogeapi.php';

$dogeAPIKey = "mi api key";

$doge = new DogeAPI();

$validKey = $doge->set_key($dogeAPIKey);

if($validKey) {
    echo "Yay, it's a valid API key\n\n<br><br>";
    $balance = $doge->get_balance();
    $address = $doge->get_my_addresses(); 
    $difficulty = $doge->get_difficulty();
    $current_block = $doge->get_current_block();
    echo "Your current balance is " . $balance . "Ɖ\n";
    //echo "Your current address is " . print_r($address,true) . "\n";
    //echo "The current difficulty is " . $difficulty . "\n";
    //echo "The current block is " . $current_block . "\n";
} else {
  echo "The API Key (" . $doge->get_key() . ") is not a valid API key";
}
?>
y el resultado:

Yay, it's a valid API key

Catchable fatal error: Object of class stdClass could not be converted to string in /home2/coinspai/public_html/dados/lib/testdogeapi.php on line 16

Alguien sabe como solucionar esto?
  #2 (permalink)  
Antiguo 17/05/2014, 07:51
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 16 años, 11 meses
Puntos: 292
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

Haz un ..

Código PHP:
Ver original
  1. var_dump ($balance);

Te lo digo para poder decirte de ahi que propiedad es la que necesitas que sea imprimible aunque lo raro es que segun la API

Cita:
get_balance()
Returns the DOGE balance of your entire account to 8 decimal places.

/wow/?api_key={API_KEY}&a=get_balance

Desde ya ese objeto es generico y no tiene por tanto implementado el metodo __toString()
__________________
Salu2!
  #3 (permalink)  
Antiguo 17/05/2014, 07:55
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

Listo, esta asi:

$balance = $doge->get_balance();
var_dump($balance);
  #4 (permalink)  
Antiguo 17/05/2014, 07:56
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 16 años, 11 meses
Puntos: 292
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

EMMMMMMMMMMMMMM... y el resultado ??? que te imprime ese var_dump() ???

Lo raro es que segun la API

Cita:
get_balance()
Returns the DOGE balance of your entire account to 8 decimal places.

/wow/?api_key={API_KEY}&a=get_balance
Pero ya veremos......
__________________
Salu2!
  #5 (permalink)  
Antiguo 17/05/2014, 07:57
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

resultado aqui: http://dados.coinspain.es/lib/testdogeapi.php

Cita:
Yay, it's a valid API key

object(stdClass)#2 (1) { ["data"]=> object(stdClass)#3 (1) { ["balance"]=> int(0) } }
  #6 (permalink)  
Antiguo 17/05/2014, 08:16
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 16 años, 11 meses
Puntos: 292
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

Segun ese anidamiento de objetos:

Código PHP:
object(stdClass)#2 (1) 


    [
"data"]=> object(stdClass)#3 (1) 
    


        [
"balance"]=> int(0
    } 


Quedaria (creo) asi:

Código PHP:
Ver original
  1. $balance = $doge->get_balance()->data->balance;

Vas a ver.. el balance en este caso es 0
__________________
Salu2!
  #7 (permalink)  
Antiguo 17/05/2014, 08:20
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

Muchisimas gracias!! Solucionado!
  #8 (permalink)  
Antiguo 17/05/2014, 08:25
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

Ups, tengo otro problema xD

Como selecciono 1 de las 3 array que me salen en las direcciones?

$address = $doge->get_my_addresses()->data->addresses;
echo "Your current address is " . print_r($address,true) . "\n<br>";


Resultado:
Your current address is Array ( [0] => DPZ4bskFKPGDh4MSytLQDSgHwsNbc61TqM [1] => DGkvydJxfvDGC4WJNjRrU6tJyP4rZo8XBf [2] => DDoG2tvfKQJG2HzwP6qVJc99ijA8QNYAPF )
  #9 (permalink)  
Antiguo 17/05/2014, 08:27
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Catchable fatal error: Object of class stdClass could not be converted to

Probe

$address = $doge->get_my_addresses()->data->addresses[0];

y funciono :)

Etiquetas: class, fatal, html, object, stdclass, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:33.