0
我試圖得到朋友的名字和個人資料照片作爲一個獨立的變量數據解析爲Facebook PHP響應
$friendpic1 = url;
$friendname1 = name;
$friendpic2 = url;
$friendname2 = name;
<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication('xxxxxxx','xxxxxx');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('xxxxxxxx');
try {
$session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
} catch(Exception $ex) {
// When validation fails or other local issues
}
// see if we have a session
if (isset($session)) {
// graph api request for user data
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id');
$name = $graphObject->getProperty('name');
$email = $graphObject->getProperty('email');
///////////////////////////////////////
$request1 = new FacebookRequest($session, 'GET', '/me/invitable_friends?fields=id,name,picture.type(normal)&limit=5');
$response1 = $request1->execute();
$graphObject1 = $response1->getGraphObject();
$fname = $graphObject1->AsArray();
} else {
$permissions = ['email', 'user_friends'];
$loginUrl = $helper->getLoginUrl($permissions);
header("Location: ".$loginUrl);
}
?>
我無法解析響應。
它是在stdClass請告訴我任何方式它可以做到。
響應
array(5){
[
0
] => object(stdClass)#13 (3) {
[
"id"
] => string(110) "AVlkiLpj2OrXVjBe2xqHHpZHmVx8WedF28ZakdPf5ixuiRbBh1gmT0AELmxpFFbKazQmajZTbHVOCQn4PTkhyYsAEYm2wY2zma76LKNgAzixUA" [
"name"
] => string(18) "Shivnarayan Jangid" [
"picture"
] => object(stdClass)#14 (1) {
[
"data"
] => object(stdClass)#15 (2) {
[
"is_silhouette"
] => bool(false) [
"url"
] => string(208) "https://fb-s-c-a.akamaihd.net/h-ak-xal1/v/t1.0-1/p100x100/12316239_849133168517451_5573830579729777887_n.jpg?oh=381a001796f172460edb1c12978c238c&oe=58E447AA&__gda__=1495195363_4166d52205da017e520efe2c8f82903e"
}
}
} [
1
] => object(stdClass)#16 (3) {
[
"id"
] => string(110) "AVnm3bQQ_mEuMO-g42H2XrenRK29xWkYHoWofvSo_Yn_XFiNjTXKHAQ6Csw6aW-yYmm_qpxsYmi39daIXDavdGkG9xmdc5Y2f270Vs8Hc4LyPQ" [
"name"
] => string(12) "Sameer Katwe" [
"picture"
] => object(stdClass)#17 (1) {
[
"data"
] => object(stdClass)#18 (2) {
[
"is_silhouette"
] => bool(false) [
"url"
] => string(208) "https://fb-s-a-a.akamaihd.net/h-ak-xfp1/v/t1.0-1/p100x100/14910502_950715611701314_5931625519981925021_n.jpg?oh=62ad41fdda91148c2ddb090c97458eec&oe=58DCE0BB&__gda__=1490455729_314dd8295133cdd14c5103b39475e0bb"
}
}
} [
2
] => object(stdClass)#19 (3) {
[
"id"
] => string(110) "AVnEvaz_3htMOQeXHdzUZfacq1CjJvVVOFWFJEw9s5rx4FORE6rSQZsJFrsrSWtjh_F6v6mxGheEksHvIjDbDHxye7Juu9l_IvqpAM4nFJQbbA" [
"name"
] => string(13) "Leethan Rohit" [
"picture"
] => object(stdClass)#20 (1) {
[
"data"
] => object(stdClass)#21 (2) {
[
"is_silhouette"
] => bool(false) [
"url"
] => string(205) "https://fb-s-c-a.akamaihd.net/h-ak-xap1/v/t1.0-1/s100x100/65527_322856177899716_8103687485969238374_n.jpg?oh=e4a04c8684a5b81164d6c75847c2ad04&oe=58E2E797&__gda__=1490586919_6cfa9ebe2ee48ce330dca69c6649c243"
}
}
} [
3
] => object(stdClass)#22 (3) {
[
"id"
] => string(110) "AVnOxJCFtbRoQrG29sslnNU86Svf0UdFJqgbEtiwDxpLn6UusccSfkoYXBVMjwSFesJeQ2ZjIxAKO_cto0Rk3TQEjNv3HNs-DvvD8oOTHBlKSw" [
"name"
] => string(12) "Neelam Katwe" [
"picture"
] => object(stdClass)#23 (1) {
[
"data"
] => object(stdClass)#24 (2) {
[
"is_silhouette"
] => bool(false) [
"url"
] => string(209) "https://fb-s-b-a.akamaihd.net/h-ak-xlp1/v/t1.0-1/p100x100/15740997_1283628385045517_1812997983243581871_n.jpg?oh=996b081ccd71dedd089c3962fa5b8601&oe=59204A2D&__gda__=1491618514_28f82c5503155a427524335c5bc13fd8"
}
}
} [
4
] => object(stdClass)#25 (3) {
[
"id"
] => string(110) "AVkWJI3EDTVLMguVpWETaOU6OzZpKOySJ9Gi9xtUuPMeSYxoLzu6JQLYE3H-sqKcpM9Ryu6xEvVSh_yFGUT57Q6Xu8zLAmaxx4Om4V9Hu2CEdA" [
"name"
] => string(11) "Divya Gupta" [
"picture"
] => object(stdClass)#26 (1) {
[
"data"
] => object(stdClass)#27 (2) {
[
"is_silhouette"
] => bool(false) [
"url"
] => string(209) "https://fb-s-c-a.akamaihd.net/h-ak-xtp1/v/t1.0-1/p100x100/14212681_1091771700909665_1239783294366264056_n.jpg?oh=93e82a4f8a6d07acefea89db90ecf5de&oe=58E6B605&__gda__=1491009063_4737ca28022c4613d8f1d776eddcd5ae"
}
}
}
}object(stdClass)#28 (2){
[
"cursors"
] => object(stdClass)#29 (2) {
[
"before"
] => string(124) "QVFIUjdFbG0wNXVBZAm5NSU5Xdkt4VmRDaXIwR2Jxcjc3YXNNUGNaRVJkTnlOMUlraUw1VVhTTkhHVEhRX3ZAEMW9uLVo5alNoU0hJeWJWajZAQMEZAVeEo1R3dB" [
"after"
] => string(122) "QVFIUlFNMmV5YVZABU3JKTUZApOW82Q0dtSzdmd3FpN2p2d085SE1hbEI1bEo5UVFmV25TTEpJNmVVbGp3RllKYjhpWndTeHpObWdWcWdjSVR5cEptVENmUTN3"
} [
"next"
] => string(439) "https://graph.facebook.com/v2.8/1871548009745987/invitable_friends?access_token=EAAFOxTjmzpIBANWIalY14b1zJJi38C49OdQyz1sjwtrY39dLHRhDsS0rd0ZAYiLEkSZAGBee3pedid5vc7cI7wSNWewsZBLqKI6QP8WHGaSw7BoJ08FEWnl9x4VX9ZCPXGzvZBqvbYReZCuPT4OWHFWRQLZCoW3m44zoWQK0xgS8QZDZD&fields=id%2Cname%2Cpicture.type%28normal%29&limit=5&after=QVFIUlFNMmV5YVZABU3JKTUZApOW82Q0dtSzdmd3FpN2p2d085SE1hbEI1bEo5UVFmV25TTEpJNmVVbGp3RllKYjhpWndTeHpObWdWcWdjSVR5cEptVENmUTN3"
}
上述響應我得到如何獲得單獨的變量每個配置文件照片。
'$ friendpic = $ graphObject1 [0] - > picture-> data-> url; '不起作用。 – user7364693