无法获得facebook访问令牌?

时间:2013-09-24 17:54:31

标签: php facebook facebook-php-sdk

我正在尝试在使用PHP(Codeigniter)执行脚本后将网址/状态发布到我的Facebook页面。目前我收到以下错误uncaught oauthexception invalid oauth access token signature.我知道问题与我的访问令牌错误有关,但无论我在Facebook上阅读了多少文档,我似乎无法弄明白。有人可以给我一个关于如何获得访问令牌的解决方案吗?

        include('system/libraries/facebook.php');

    if($this->session->userdata('level') == "admin"){

        $role = $this->input->post('role');
        $company = $this->input->post('company');
        $location = str_replace( '+', ' ', $this->input->post('location') );
        $category = str_replace( '+', ' ', $this->input->post('category') );
        $type = str_replace( '+', ' ', $this->input->post('type') );
        $description = $this->input->post('description');
        $extract = $this->input->post('extract');           
        $date = time();
        $link = $this->input->post('link');

        if($this->input->post('closing_date')){
            $closing_date = $this->input->post('closing_date');
            $closing_date = str_replace('/', '-', $closing_date);
            $closing_date = strtotime($closing_date);
        }else{
            $closing_date = time() + 2592000;
        }

        $url = str_replace(' ', '-', trim($role));
        $location_dash = str_replace(' ', '-', trim($location));
        $url = $url."-in-".$location_dash;

        $this->db->set('role', $role);
        $this->db->set('company', $company);
        $this->db->set('type', $type);
        $this->db->set('location', $location);
        $this->db->set('category', $category);
        $this->db->set('url', strtolower($url));            
        $this->db->set('description', $description);
        $this->db->set('extract', $extract);            
        $this->db->set('link', $link);          
        $this->db->set('time', $date);
        $this->db->set('closing_date', $closing_date);
        $this->db->set('active', 1);

        $this->db->insert('jobs');  

        $job = $this->db->get_where('jobs', array('time' => $date ))->row_array();

        $url = "http://www.example.com/job/view/".$job['id']."/".$job['url']."";

        $facebook = new Facebook(array(
          'appId'  => '***',
          'secret' => '***'
        ));

        $message = array(
        'access_token' => "***",
        'message'=> "".$url.""
        );

        $facebook->api('/me/accounts','POST', $message);            

1 个答案:

答案 0 :(得分:1)

您是如何从您的网站登录Facebook的?您需要确保使用

$loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_actions'));

publish_actions范围允许您的应用程序代表用户发布帖子

然后使用:

$message = array(
    'access_token' => $facebook->getAccessToken(), // Get current access_token
    'message'=> "".$url.""
);

$facebook->api('/me/accounts','POST', $message);

它应该成功发布

希望能解决问题!