Issue
I'm currently trying to post a url/status to my facebook page after executing a script with PHP (Codeigniter). At the moment I am getting the following error uncaught oauthexception invalid oauth access token signature.
I know the problem is something to do with the fact my access token is wrong but no matter how much documentation I read on Facebook I can't seem to figure it out. Could someone give me a solution as to how I would get the 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);
Solution
How have you logged in with Facebook from your website? You need to make sure that you use
$loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_actions'));
publish_actions
scope allows your application to make posts on the users behalf
Then use:
$message = array(
'access_token' => $facebook->getAccessToken(), // Get current access_token
'message'=> "".$url.""
);
$facebook->api('/me/accounts','POST', $message);
And it should post successfully
Hope that solves the problem!
Answered By - GroovyCarrot
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.