【问题标题】:How to setup Facebook sdk with CodeIgniter to do a Facebook fan Page Tab?如何使用 CodeIgniter 设置 Facebook sdk 来创建 Facebook 粉丝页面选项卡?
【发布时间】:2014-02-17 11:12:56
【问题描述】:

我正在尝试以下方法:

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Welcome extends CI_Controller {

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

        $this->load->library('facebook', $this->config->item('fb_config'));
    }

    public function index() {
        $user_id = $this->facebook->getUser();
        $data['user_id'] = $user_id;

        if ($user_id) {

            // We have a user ID, so probably a logged in user.
            // If not, we'll get an exception, which we handle below.
            try {

                $user_profile = $this->facebook->api('/me', 'GET');
                echo "Name: " . $user_profile['name'];
            } catch (FacebookApiException $e) {
                // If the user is logged out, you can have a 
                // user ID even though the access token is invalid.
                // In this case, we'll get an exception, so we'll
                // just ask the user to login again here.
                $login_url = $this->facebook->getLoginUrl();
                echo 'Please <a href="' . $login_url . '">login.</a>';
                error_log($e->getType());
                error_log($e->getMessage());
            }
        } else {

            // No user, print a link for the user to login
            $login_url = $this->facebook->getLoginUrl();
            echo 'Please <a href="' . $login_url . '">login.</a>';
        }
        die;
    }

}

但我收到此错误:

Invalid or no certificate authority found, using bundled information
OAuthException
Error validating access token: The user has not authorized application XXXXXXXXX.

我能做些什么来解决这个问题?这不是要求用户访问他的个人资料的正确方法吗? 以及如何像在 javascript 中那样添加一些范围

{scope: 'email, user_birthday'}

【问题讨论】:

    标签: php facebook codeigniter facebook-php-sdk


    【解决方案1】:

    发现问题出在 $this->config->item('fb_config') 数组中 应该是这样的:

    $config['fb_config'] = array(
        'appId' => 'YOUR_APP_ID',
        'secret' => 'YOUR_APP_SECRET',
        'fileUpload' => false, // optional
        'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-25
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多