duanliao5995 2016-01-30 20:28
浏览 63
已采纳

可捕获的致命错误:类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;

?>

展开全部

  • 写回答

2条回答 默认 最新

  • dongya6997 2016-01-30 22:04
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部