我很难从mashape中获得任何数据,我已经发布了UNIREST的帖子,但是我无法将数据反馈给自己,这就是调用应该返回的内容;
{
"result": {
"name": "The Elder Scrolls V: Skyrim",
"score": "92",
"rlsdate": "2011-11-11",
"genre": "Role-Playing",
"rating": "M",
"platform": "PlayStation 3",
"publisher": "Bethesda Softworks",
"developer": "Bethesda Game Studios",
"url": "http://www.metacritic.com/game/playstation-3/the-elder-scrolls-v-skyrim"
}
}我的密码..。
require_once 'MYDIR/mashape/unirest-php/lib/Unirest.php';
$response = Unirest::post(
"https://byroredux-metacritic.p.mashape.com/find/game",
array(
"X-Mashape-Authorization" => "MY API AUTH CODE"
),
array(
"title" => "The Elder Scrolls V: Skyrim",
"platform" => undefined
)
);
echo "$response->body->name";
?>有人能建议我怎样才能让它呼应“名字”吗。
如能提供任何帮助,将不胜感激:)
发布于 2014-06-03 18:54:30
您试图显示主体的方式似乎是阻止您在响应中看到错误,告诉您属性platform必须是number。
尝试使用json_encode($response->body)来查看完整的响应:
<?php
require_once 'lib/Unirest.php';
$response = Unirest::post(
"https://byroredux-metacritic.p.mashape.com/find/game",
array(
"X-Mashape-Authorization" => "-- your authorization key goes here --"
),
array(
"title" => "The Elder Scrolls V: Skyrim",
"platform" => 1 # try placing undefined here.
)
);
echo json_encode($response->body);
?>一旦得到响应,就可以使用$response->body->result->name
$result = $response->body->result;
echo "{$result->name} has a score of [{$result->score}]";https://stackoverflow.com/questions/24011511
复制相似问题