Reputation: 1951
i wrote a function to post a photo to a users wall and it raises the following exception
Fatal error: Uncaught OAuthException: A user access token is required to request this resource. thrown in C:\xampp\htdocs\upd8r\application\helpers\base_facebook.php on line 1039
this is my code- what am i missing?
function facebook_img_post($fb_id,$data){
$this->load->helper('facebook');
$this->load->model('mmaster');
$globalSettings = $this->mmaster->getGlobalSettings('1');
// Create our Application instance.
$this->facebook = new Facebook(array(
'appId' => $globalSettings['facebook_id'],
'secret' => $globalSettings['facebook_secret'],
'cookie' => false
));
$this->facebook->setFileUploadSupport(true);
$this->facebook->api("/".$fb_id."/photos",'post', array(
'message'=> $data['message'],
'source' => $data['source']
)
);
//new fb post
}
update
this is the link the user registered with showing all the permissions requested
$data['loginUrl'] = $this->facebook->getLoginUrl(array('scope' => 'read_stream,publish_stream,status_update,offline_access'))
update 2
I swapped the api out and tried it with curl to have more control and apparently i need a user access token- even though i was retrieving and using an application access token- apparently there are two different ones.
Upvotes: 1
Views: 181
Reputation: 14312
You need to have the user grant you publish_stream
and manage_page
permissions also to do this when you get the loginURL, e.g.
$loginUrl = $facebook->getLoginUrl(
array(
'scope' =>'user_status,user_photos,status_update,manage_pages,publish_stream,offline_access',
'redirect_uri' => $fbconfig['baseurl']
)
);
Here's some more info: FB permissions: http://developers.facebook.com/docs/reference/api/permissions/
Tutorial for connecting to FB including asking for permissions: http://thinkdiff.net/facebook/php-sdk-3-0-graph-api-base-facebook-connect-tutorial/
Upvotes: 1
Reputation: 6030
you need to request an access token with publish_stream
permission
check out this links:
UPDATE
after creating an instance for new Facebook
you have to redirect to the FB for user authentication:
$loginUrl = $this->facebook->getLoginUrl(array('scope' => 'publish_stream, offline_access'));
echo '<script>top.location.href="'.$loginUrl.'"</script>';
second update
if you're doing all in this way and the problem still exists, then maybe you're passing the image data to curl incorrectly. You must prepend image path with @
to inform CURL that it must send the image as multipart data.
Upvotes: 1