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.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型