duanliao5995 2016-01-31 04: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-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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?