【发布时间】:2012-12-07 06:27:33
【问题描述】:
我正在尝试使用 stdclass 从 Facebook 的图形 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 但没用。
任何帮助将不胜感激。
谢谢!
【问题讨论】:
-
Facebook 开发者论坛有一些人强烈建议您使用 cURL 而不是
file_get_contents(),因为有些人抱怨它会混淆几个字符。在这种情况下,它非常简单,但您可能不想在获取access_token或类似的情况下使用它。
标签: php arrays facebook-graph-api