【问题标题】:Unable to retrieve email through Facebook API无法通过 Facebook API 检索电子邮件
【发布时间】:2015-11-16 17:41:51
【问题描述】:

我在 CodeIgniter 框架中使用 Facebook API 登录;我能够检索用户名和 ID,但无法收到电子邮件。我已阅读有关权限的信息,但在这方面没有任何线索。

我的控制器:

public function login()
{

        $this->load->library('facebook');

        $user = $this->facebook->getUser();


        if ($user) {
            try {
                $data['user_profile'] = $this->facebook->api('/me');
            } catch (FacebookApiException $e) {
                $user = null;
            }
        }else {
            // Solves first time login issue. (Issue: #10)
            $this->facebook->destroySession();
        }
        if ($user) {
            $data['logout_url'] = site_url('user_module/facebook_logout'); // Logs off application
            // OR 
            // Logs off FB!
            // $data['logout_url'] = $this->facebook->getLogoutUrl();
        } else {
            $data['login_url'] = $this->facebook->getLoginUrl(array(
           // 'redirect_uri' => site_url('user_module/home'),
            'scope' => array("email") // permissions here
            ));
        }

        $this->load->view('user_login',$data);
}  

视图文件:

<?php if (@$user_profile):  // call var_dump($user_profile) to view all data ?>
     <div class="row">
         <div class="col-lg-12 text-center">
             <img class="img-thumbnail" data-src="holder.js/140x140" alt="140x140" src="https://graph.facebook.com/<?=$user_profile['id']?>/picture?type=large" style="width: 140px; height: 140px;">
             <h2><?=$user_profile['name']?></h2>
             <h2><?=$user_profile['id']?></h2>
             <h2><?=$user_profile['email']?></h2>
             <h2><?=$user_profile['user_location']?></h2>
             <a href="<?=$user_profile['link']?>" class="btn btn-lg btn-default btn-block" role="button">View Profile</a>
             <a href="<?= $logout_url ?>" class="btn btn-lg btn-primary btn-block" role="button">Logout</a>
         </div>
     </div>
<?php else: ?>
      <h2 class="form-signin-heading">Login with Facebook</h2>
      <a href="<?= $login_url ?>" class="btn btn-lg btn-success btn-block" role="button">Login</a>
<?php endif; ?>

【问题讨论】:

  • 欢迎来到 Stack Overflow!我编辑了您的问题,以便回答您的​​用户更容易理解。祝你好运!

标签: php facebook codeigniter


【解决方案1】:

“声明性字段”是您需要的,请参阅更新日志:https://developers.facebook.com/docs/apps/changelog#v2_4

例如:$this-&gt;facebook-&gt;api('/me?fields=name,email')

【讨论】:

  • 显示此错误:- 未设置应用程序:此应用程序仍处于开发模式,您无权访问它。切换到已注册的测试用户或向应用管理员请求权限。
  • 好吧,错误消息与您的问题完全无关,并且不言自明。您的应用未上线,并且您不是作为在应用中具有角色的用户尝试。
  • 我使用的是本地主机,我应该使用我的域名吗?
  • 这也无关紧要...只需将其上线或使用应用管理员,并确保设置正常
  • 它在管理员 ID 下工作正常,但在我的测试 ID 下无法正常工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多