dongxikuo5171 2012-03-24 14:55
浏览 20
已采纳

无法通过脸谱图api检索信息

I am trying to retrieve information through Facebook graph api, using the below code which is returning me nothing, I wrote this code after getting help from on line documentations etc. but it's not working.

Kindly help me with this.

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];

I treid them all but nothing is working.

  • 写回答

1条回答 默认 最新

  • dsy6639 2012-03-24 17:15
    关注

    you need to echo from the user_profile array. Try like below $user_profile[name]; its weird with no quotes to string from but that is how we access the arrays.

    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];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等