try {
$requestCover = $fb->get('me?fields=cover'); //getting user Cover
$requestProfileCover=$fb->get('/me');
// $cover = $requestCover->getGraphUser();
// $profile = $requestProfileCover->getGraphUser();
}
catch(Facebook\Exceptions\FacebookResponseException $e) {
echo ' error: ' . $e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK error: ' . $e->getMessage();
exit;
}
print_r($requestCover); // showing cover details on the screen
echo "<img src='".$requestCover['source']."'/>";
错误:
致命错误:未捕获错误:无法使用类型的对象 Facebook\FacebookResponse 作为数组 C:\xampp\htdocs b_app wibook\index.php:165 堆栈跟踪: #0 {main} 扔在 C:\xampp\htdocs b_app wibook\index.php 第 165 行
CBroe 正在向您指出要使用的正确函数来获取数据。我使用这个答案是为了解释你应该尝试的内容不太适合评论。 (还没有使用过这个api,所以我不确定你的问题的实际解决方案,但处理你的问题的描述应该是准确的)
通过调用
$requestCover = $fb->get('me?fields=cover');
,您将 $requestCover
设置为 FacebookResponse
类的对象。
因为它是一个对象,所以您无法像处理数组元素一样访问它的属性。如果它们是公共的,您要么必须使用
->
运算符来访问它们,要么必须使用特定的方法。
在这种情况下,对于类
FacebookResponse
,你必须使用一些方法。 CBroe 向您指出的那个,将返回一个包含响应正文的不同数据的数组,因此首先将调用此方法的返回值写入变量,然后您(应该)拥有一个包含您的价值观。
try {
$requestCover = $fb->get('me?fields=cover'); //getting user Cover
$requestProfileCover=$fb->get('/me');
}
catch(Facebook\Exceptions\FacebookResponseException $e) {
echo ' error: ' . $e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK error: ' . $e->getMessage();
exit;
}
$responseBody = $requestCover->getDecodedBody();
echo "<img src='" . $responseBody ['source'] . "'/>";
print_r($requestCover); // should print an array