【发布时间】:2015-07-14 15:26:25
【问题描述】:
我确定我错过了什么,但目前我不明白是什么。
我正在玩 Guzzle,我正在尝试获取页面信息:
<?php
/**
* Example of usage of APIConnect to get information
* about a Facebook Page through Graph API.
*/
require('../vendor/autoload.php');
/** SET HERE A PAGE */
$page = 'SamplePage';
$remoteUrl = 'https://graph.facebook.com/' . $page;
$client = new GuzzleHttp\Client();
$res = $client->get($remoteUrl);
echo $res->getStatusCode();
// "200"
echo $res->getHeader('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// {"type":"User"...'
这是 Guzzle 文档显示的代码。
现在,我希望调用此代码会返回一些对象,这些对象在其属性之一中包含以下 JSON 响应,因为如果我直接在浏览器中调用 URL,我会收到该响应:
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException",
"code": 104
}
}
为什么相反,如果我使用 Guzzle 方法获取响应值,我看到的是 null?我错过了什么?
【问题讨论】: