【问题标题】:Unable to retrieve information through facebook graph api无法通过 facebook graph api 检索信息
【发布时间】:2012-03-24 14:55:27
【问题描述】:

我正在尝试通过 Facebook 图形 api 检索信息,使用下面的代码没有返回任何内容,我在从在线文档等获得帮助后编写了此代码,但它不起作用。

请帮我解决这个问题。

include ('src/facebook.php');    
$app_id = "160336957418730";
$app_secret = "************************";
        $facebook = new Facebook( array('appId' => $app_id, 'secret' => $app_secret, ));

        $user = $facebook -> getUser();
        if ($user) {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $user_profile = $facebook -> api('/me');
                //$user_profile = $facebook->api('/me/home');
            } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
            }
        }
        echo $user_profile[name];
        echo $user_profile[id];
        echo $user_profile[picture];

我把它们都用了,但没有任何效果。

【问题讨论】:

    标签: php facebook facebook-graph-api facebook-php-sdk facebook-authentication


    【解决方案1】:

    您需要从 user_profile 数组中回显。尝试如下 $user_profile[name];这很奇怪,没有引号作为字符串,但这就是我们访问数组的方式。

    include ('src/facebook.php');    
    $app_id = "160336957418730";
    $app_secret = "************************";
    $facebook = new Facebook( array('appId' => $app_id, 'secret' => $app_secret, ));
    $user = $facebook->getUser();
    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
        //$user_profile = $facebook->api('/me/home');
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }
            echo $user_profile[name];
            echo $user_profile[id];
            echo $user_profile[picture];
    

    【讨论】:

    • 我已经用这个更新了我的代码,但它仍然不起作用?没有输出..任何可能的原因?
    • 您是否已授予您应用程序查看您的基本信息的权限?
    猜你喜欢
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 2015-12-19
    • 2012-10-23
    • 1970-01-01
    相关资源
    最近更新 更多