-1

我目前正在尝试在使用 PHP(Codeigniter)执行脚本后将 url/status 发布到我的 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);            
4

1 回答 1

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);

它应该成功发布

希望能解决问题!

于 2013-09-24T21:29:50.310 回答