0

嗨,我正在尝试从他们的 Facebook 个人资料中提取用户的大学,并发现这篇文章很有用 - Getting Education with Facebook Graph API in PHP

但是,在我的实现中,由于某种原因无法识别“教育”字段,并且在“未定义索引:教育”的浏览器中引发错误。这很奇怪,因为名字和姓氏以及性别都可以正常检索,但“教育”字段却没有。

有谁知道为什么会这样?

我的代码:

// 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;
    }
}
4

1 回答 1

0

从用户教育栏,您可以阅读 facebook 用户的学校名称、id 和类型。只需在运行 fql 的变量中获取学校名称。欲了解更多信息请检查:https ://developers.facebook.com/docs/reference/fql/user/

于 2012-07-20T16:21:18.143 回答