duanliao5995 2016-01-31 04:28
浏览 61
已采纳

可捕获的致命错误:类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-31 06: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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?