dongya6395 2013-06-07 21:06
浏览 72
已采纳

redirect_uri URL必须是绝对的Facebook登录PHP SDK

I am trying to implement the facebook login in my project in codeigniter.

I am using the php sdk.

When I click on the login button, it gives me an error:

The redirect_uri URL must be absolute

What is the problem and how do I fix it?

Here is the contents of view/home.php:

 <?php if(!$fb_data['me']): ?>
  Please login with your FB account: 
  <a href="<?php echo $fb_data['loginUrl']; ?>">login</a>
  <?php else: ?>
  <img src="https://graph.facebook.com/<?php 
    echo $fb_data['uid']; ?>/picture" alt="" class="pic" />
  <p>Hi <?php echo $fb_data['me']['name']; ?>,<br />
    <a href="<?php 
    echo site_url('welcome/topsecret'); ?>">
    You can access the top secret page</a> or 
    <a href="<?php echo $fb_data['logoutUrl']; ?>">logout</a> </p>
  <?php endif; ?>

Here is the contents of: controler/home.php

class Home extends CI_Controller {

   function __construct()
    {
        parent::__construct();

        $this->load->model('Facebook_model');
    }

    function index(){
        $this->load->model("Concertos_model");
        $data['banners'] = $this->Concertos_model->get_banner_data();


       $fb_data = $this->session->userdata('fb_data'); // This array contains all the user FB information

        $data = array(
                    'fb_data' => $fb_data,
                    );

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

    }

    function topsecret()
    {
        $fb_data = $this->session->userdata('fb_data');

        if((!$fb_data['uid']) or (!$fb_data['me']))
        {
            redirect('home');
        }
        else
        {
            $data = array(
                        'fb_data' => $fb_data,
                        );

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

}

Contents of: model/Facebook_model.php:

<?php
class Facebook_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();

        $config = array(
                        'appId'  => 'xxxxxxxxxxxxxxxxxxx',
                        'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxx',
                        'fileUpload' => true, // Indicates if the CURL based @ syntax for file uploads is enabled.
                        );

        $this->load->library('Facebook', $config);

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

        // We may or may not have this data based on whether the user is logged in.
        //
        // If we have a $user id here, it means we know the user is logged into
        // Facebook, but we don't know if the access token is valid. An access
        // token is invalid if the user logged out of Facebook.
        $profile = null;
        if($user)
        {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $profile = $this->facebook->api('/me?fields=id,name,link,email');
            } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
            }
        }

        $fb_data = array(
                        'me' => $profile,
                        'uid' => $user,
                        'loginUrl' => $this->facebook->getLoginUrl(
                            array(
                                'scope' => 'email,user_birthday,publish_stream', // app permissions
                                'redirect_uri' => 'home' // URL where you want to redirect your users after a successful login
                            )
                        ),
                        'logoutUrl' => $this->facebook->getLogoutUrl(),
                    );

        $this->session->set_userdata('fb_data', $fb_data);
    }
}

Why does facebook return that message and how do I fix it?

  • 写回答

1条回答 默认 最新

  • duanpenpan5796 2013-06-07 21:11
    关注
    'redirect_uri' => 'home' // URL where you want to redirect your users after a successful login
    

    You have to provide full URL (starting from http://), not CI page alias. Use site_url('home') instead

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题