可捕获的致命错误:类stdClass的对象无法转换为字符串/无返回

问题描述:

The problem is that $price return nothing.

I'm using https://github.com/PHPGangsta/GoogleAuthenticator for the TOTP part of the code.

I have tried to play around with settype() for the $price, but seems like it doesn't really work.

If I change $obj->data->prices[0]->price to $obj->data. I get this error

Catchable fatal error: Object of class stdClass could not be converted to string in

<?php

$secret ="(Verify Secret)";
$api = "(API Key)";

require_once 'GoogleAuthenticator.php';

$ga = new PHPGangsta_GoogleAuthenticator();

$oneCode = $ga->getCode($secret);

$itemName=str_replace(array(' ','"','\'','\\\'','\\'),array('%20',null,null,null,null),$_GET['name']);

$url = "https://bitskins.com/api/v1/get_item_price/?api_key=" . $api . "&code=" . $oneCode . "&names=" . $itemName . "&delimiter=!END!";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$obj = curl_exec($curl);
$obj = json_decode(curl_exec($curl));
curl_close($curl);

$price = $obj->data->prices[0]->price;

echo "Price: ".$price."<br>";
echo "itemName: ".$itemName."<br>";
echo "url: ".$url;

?>

Well, this is kind of embarrassing as the problem is that I disabled API access shortly and forgot to turn it on again.

What kind of debugging have you done? Have you done a var_dump() for each var you've declared to see what gets returned?

I looked at the bitskins api, and I don't see "get_item_price" as an option.

Are you sure that you don't mean to use get_price_data_for_items_on_sale?