hderanga
hderanga

Reputation: 1279

Upload photo to facebook page as non admin

I was struggling to find a way to do this. may be this is not possible but I did not found any resource saying this can't do. so I think to post on here.

I am developing a Facebook application and It has photo uploading function. what I was trying to do is, when the user upload an image then image will automatically add to my fan page.

so I go through like this. but it is only possible for admin. (I hard code admin user id)

$fanpageId  = 562**23; //My Facebook fanpage ID
$adminFbId  = 100***12; // facebook user ID of admin (Fanpage)
    try{              
         $pagesInfo = $facebook->api("/100***00/accounts");               
    }
catch (FacebookApiException $e){              
     echo $e;     
 }

     foreach($pagesInfo["data"] as $page) {
     if($page["id"] == $fanpageId) {
        $page_access_token = $page["access_token"];
        break;
    }
}

if( !empty($page_access_token) ) {
    $args = array(
        'access_token'  => $page_access_token,
        'message'       => "I'm a Page from test!"
    );
    $post_id = $facebook->api("/$fanpageId/feed","post",$args);
    // sucess...
}

Is there any possible way to give page admin rights for the App or force api to use admin access token to post ?

Upvotes: 0

Views: 743

Answers (2)

hderanga
hderanga

Reputation: 1279

Thanks a lot I think am getting some progress. I did what you say, now message is posting on fan page. then I try to upload an image. this is what I did

$args = array(
        'access_token'  => $access_token,
    'image' => '@/my/upload/file/path/'.$fileName
    );

try{          
    $post_id = $facebook->api("/".$fanpageId."/photos","post",$args);             
}
catch (FacebookApiException $e){
    echo $e;              
}

But its throwing an exception :OAuthException: An unknown error has occurred.

I set user permisson as : publish_stream,photo_upload,user_photos

Upvotes: 1

Sahil Mittal
Sahil Mittal

Reputation: 20753

Why are you using the page access token, if you want your user to post on the fanpage?

Simply, replace the access_token in $args with the access token of the user with publish_stream permission.

The post will be published on the fanpage, on behalf of the user via your app .

Upvotes: 1

Related Questions