php - Unable to get the facebook access token? -
i'm trying post url/status facebook page after executing script php (codeigniter). @ moment getting following error uncaught oauthexception invalid oauth access token signature.
know problem fact access token wrong no matter how documentation read on facebook can't seem figure out. give me solution how access token?
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);
how have logged in facebook website? need make sure use
$loginurl = $facebook->getloginurl(array('scope' => 'publish_actions'));
publish_actions
scope allows application make posts on users behalf
then use:
$message = array( 'access_token' => $facebook->getaccesstoken(), // current access_token 'message'=> "".$url."" ); $facebook->api('/me/accounts','post', $message);
and should post successfully
hope solves problem!
Comments
Post a Comment