我試圖使用stdclass從Facebook的圖形API獲取教育信息。這裏是陣列:在PHP中使用Facebook Graph API獲取教育
"username": "blah",
"education": [
{
"school": {
"id": "[removed]",
"name": "[removed]"
},
"year": {
"id": "[removed]",
"name": "[removed]"
},
"type": "High School"
},
{
"school": {
"id": "[removed]",
"name": "[removed]"
},
"year": {
"id": "[removed]",
"name": "[removed]"
},
"type": "College"
}
],
如何使用PHP選擇類型爲「college」的那個?下面是我用來讀取它:
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=[removed]&redirect_uri=[removed]&client_secret=[removed]&code=".$_GET['code']."";
$response = file_get_contents($token_url);
parse_str($response);
$graph_url = "https://graph.facebook.com/me?access_token="
. $access_token;
$user = json_decode(file_get_contents($graph_url));
所以名稱將是$ user-> name。
我試過$ user-> education-> school但是沒有奏效。
任何幫助,將不勝感激。
謝謝!
'var_dump($ user)' – zerkms 2011-05-30 01:31:58
Facebook開發者論壇有一些人強烈建議你使用cURL而不是'file_get_contents()',因爲有些人抱怨說它亂碼了幾個字符。 在這種情況下,它非常簡單,但您可能不想在獲取'access_token'等情況下使用它。 – Angad 2011-07-03 15:27:27