从Facebook教育 - “教育”领域提取大学不被承认

时间:2012-07-20 16:12:16

标签: facebook-graph-api

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

然而,在我的实现中,“教育”字段由于某种原因未被识别,并且在“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;
    }
}

1 个答案:

答案 0 :(得分:0)

从用户教育栏您可以阅读facebook用户的学校名称,ID和类型。只需在运行fql的变量中获取学校名称。有关详细信息,请查看:https://developers.facebook.com/docs/reference/fql/user/