首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mashape -没有显示数据?

Mashape -没有显示数据?
EN

Stack Overflow用户
提问于 2014-06-03 09:24:36
回答 1查看 844关注 0票数 0

我很难从mashape中获得任何数据,我已经发布了UNIREST的帖子,但是我无法将数据反馈给自己,这就是调用应该返回的内容;

代码语言:javascript
复制
{
 "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"
}
}

我的密码..。

代码语言:javascript
复制
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";
?>

有人能建议我怎样才能让它呼应“名字”吗。

如能提供任何帮助,将不胜感激:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-03 18:54:30

您试图显示主体的方式似乎是阻止您在响应中看到错误,告诉您属性platform必须是number

尝试使用json_encode($response->body)来查看完整的响应:

代码语言:javascript
复制
<?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

代码语言:javascript
复制
$result = $response->body->result;
echo "{$result->name} has a score of [{$result->score}]";
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24011511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档