嗨,我正在尝试从他们的Facebook个人资料中提取用户的大学,并发现这篇文章很有用- Getting Education with Facebook Graph API in PHP
然而,在我的实现中,由于某些原因,'education‘字段没有被识别,并且在浏览器中抛出了一个错误“Undefined index: education”。这很奇怪,因为名字和姓氏和性别都可以很好地检索,但不能检索“教育”字段。
有人知道为什么会这样吗?
我的代码:
// Get the app User ID
$user = $facebook->getUser();
if ($user) {
try {
// If the user has been authenticated then proceed
$user_profile = $facebook->api('/me');
// Extracting profile information to store in database
$fname = $user_profile['first_name'];
$lname = $user_profile['last_name'];
$gender = $user_profile['gender'];
$email = $user_profile['email'];
$college = null;
/* Education data is stored in an array so this iterates over
the contents of that array and checks if the entry is for "College".
*/
foreach ($user_profile['education'] as $education) { // <-ERROR HERE
if ($education['type'] == "College") {
$college = $education;
break;
}
}
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
发布于 2012-07-21 00:21:18
在用户教育栏中,你可以看到facebook用户的学校名称、id和类型。只需在运行fql的变量中获取学校名称。欲了解更多信息,请访问:https://developers.facebook.com/docs/reference/fql/user/
https://stackoverflow.com/questions/11583149
复制相似问题