Mashape API PHP -没有数据显示



我在从mashape API中获取任何数据时遇到了麻烦,我已经进行了UNIREST POST,但我无法将数据回传给自己,这就是调用应该返回的内容;

{
 "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";
?>

谁能告诉我怎样才能使它与"name"相呼应?

任何帮助都将是感激的:)

您试图显示正文的方式似乎阻止您在响应中看到错误,告诉您属性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}]";

相关内容

  • 没有找到相关文章

最新更新