我想使用invitable_friends
循环
foreach
API循环图像
$beranda = json_decode(get_html("https://graph.facebook.com/$user->id/invitable_friends?fields=id,picture,name&limit=7&access_token=$accessToken"))->data;
foreach($beranda as $friendsid){
echo '<img src="'.$friendsid->picture.'">';
}
面临此错误
Catchable fatal error: Object of class stdClass could not be converted to string in
Thia是$beranda
Array
(
[0] => stdClass Object
(
[id] => AVkUphJYSPksSJ47kLM8PGm8cOAjlNLG5NWUMp5IhdSCWkziShWsSVkRdVx1Z73jeu7B73bRzYnecUqD27V3xO36Uh27LD16mVZlRKGKgDLZIQ
[picture] => stdClass Object
(
[data] => stdClass Object
(
[is_silhouette] =>
[url] => https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/13731636_1671465926510554_2031112688215377192_n.jpg?oh=5a85a07de9ab4011e17378a38bac941c&oe=5831B7E6
)
)
[name] => Sam Saifi
)
$friendsid->picture
object(stdClass)#38 (1) {
["data"]=>
object(stdClass)#39 (2) {
["is_silhouette"]=>
bool(false)
["url"]=>
string(145) "https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/10155363_1386729058279575_5046516924942639505_n.jpg?oh=f55ea91f39815a7fb9661e65899d0a02&oe=581B8AE2"
} }
答案 0 :(得分:1)
根据您的print_r结果,您需要更改行...
echo '<img src="'.$friendsid->picture.'">';
到
echo '<img src="' . $friendsid->picture->data->url . '">';
因为你在另一个父对象中的另一个对象[picture]中的对象[data]中调用参数[url]。我会推荐一个关于面向对象的php的训练营课程,无论如何很高兴它有效!