facebook - how to post a photo to a fan page using graph api? -
i post photo fan page (as normal timeline status feed) able manage.
my app got following permissions:
email,publish_actions,read_stream,manage_pages it works own timeline. able post photo on page´s timeline. why not app?
i figered out, permission photo_upload not take effect. maybe facebook has removed it.
my app uses facebook php-sdk.
if try upload photo fan page returns me exception:
fatal error: uncaught oauthexception: (#200) subject not have permission post photos on page thrown here how access token fan page:
public function getpagedata() { $arrs = $this->facebook->api('/me/accounts'); $pagedata = new cfacebookclientpagedata(); foreach ($arrs['data'] $dataset) { if (array_key_exists('name', $dataset) && preg_match('/any\s*fan\s*page/i', $dataset['name'])) { $pagedata->scategory = $dataset['category']; $pagedata->sname = $dataset['name']; $pagedata->saccesstoken = $dataset['access_token']; $pagedata->arpermissions = $dataset['perms']; $pagedata->ipageid = $dataset['id']; } } return $pagedata; } and here how try post it:
public function uploadphoto(cfacebookclientpagedata $user, cfacebookphotodata $photo) { return $this->facebook->api('/' . $user->ipageid . '/photos', 'post', array( 'source' => '@' . realpath($photo->slocalpath), 'message' => $photo->smessage, 'access_token' => $this->saccesstoken ) ); } in other file call this:
$fb = new cfacebookclient($sappid, $ssecret); $fb->init(); $fb->setfileupload(true); $fb->init(); $user = $fb->getpagedata(); $fb->setaccesstoken($user->saccesstoken); $photo = new cfacebookphotodata(); $photo->slocalpath = 'e:\php\www\logo.png'; $photo->smimetype = 'image/png'; $photo->smessage = utf8_encode('posted fresh app :-)'); var_dump($fb->uploadphoto($user, $photo)); edit: solved mentioned in comment below: fixed in snippet not in code.
i guess you're not using page access token can receive app page via
/me/accounts the docs @ https://developers.facebook.com/docs/graph-api/reference/page/feed/#publish state that
- a user access token publish_actions permission can used publish new posts on behalf of person.
- a page access token publish_actions permission can used publish new posts on behalf of page.
Comments
Post a Comment