douzhi9395 2015-07-27 11:46
浏览 49

适用于Facebook Graph API的CodeIgniter Auth2库:未获取电子邮件地址

I am new in facebook integration with codeigniter.

I have done all setup for codeigniter oauth(0.3.1) and oauth2(0.3.1) library for 'Login with facebook' functionality.

But I am not getting email address of fb user.

I am getting only name and id from facebook.

I am not able to figure the problem.

I am using following code of CI

 public function oauth2($providername)
{

    $key = $this->config->item('key',$providername);
    $secret = $this->config->item('secret',$providername);

    $this->load->helper('url_helper');

    $this->load->spark('oauth2/0.3.1');

    $provider = $this->oauth2->provider($providername, array(
        'id' => $key,
        'secret' => $secret,
    ));
    //var_dump($provider);


    if ( ! $this->input->get('code'))
    {  

        if($providername =='facebook'){
            $url = 'http://example.com'.$provider->redirect_uri;
            redirect($url);
        }
        // By sending no options it'll come back here
       $provider->authorize();
    }
    else
    {
        // Howzit?
      //  echo "in else";die;
        try
        { 
            $token = $provider->access($_GET['code']);
            $user = $provider->get_user_info($token);
            print_r($user);die;
            $this->saveData($providername,$token,$user);

        }

        catch (OAuth2_Exception $e)
        {
            show_error('That didnt work: '.$e);
        }

    }
}

Please Help me.

Thanks

  • 写回答

2条回答 默认 最新

  • dry9192 2015-07-27 11:51
    关注

    The only way to get the users e-mail address is to request extended permissions on the email field. The user must allow you to see this and you cannot get the e-mail addresses of the user's friends.

    http://developers.facebook.com/docs/authentication/permissions

    You can do this if you are using Facebook connect by passing scope=email in the get string of your call to the Auth Dialog.

    I'd recommend using an SDK instead of file_get_contents as it makes it far easier to perform the Oauth authentication.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器