简体   繁体   中英

Posting to a user's wall using PHP

OK this has been keeping me busy for 2 days now and I'm banging my brains out now. I've posted it on forums, asked friends, googled it extensively and looked on stackoverflow. I'm not the first to post this question but I couldn't find the answer among the responses so that's why I'm creating this new question.

this is what I'm trying to do : - I want to post a message to a user's wall as a Facebook-app in PHP. - I want to do this server-to-server, so without the dialog box and any user-interaction (he could be mowing the lawn at that moment for all I care) - This user has granted permission to my app, these permissions are: 1) manage_pages, 2) publish_stream, 3) read_stream - I'm using the PHP Facebook SDK - this is my code:

/* Facebook */ 
$facebook = new Facebook(array(
    'appId'  => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_APP_SECRET
));
/* string */ 
$accessToken = $facebook->getAccessToken();
/* Array<string> */ 
$postFields = array("message"=>"test2", "access_token"=>$accessToken);

$facebook->api('/{the-id-of-the-facebook-user}/feed','post',$postFields);

this is the issue : I keep getting the following error : (#200) The user hasn't authorized the application to perform this action.

This is a bullshit-message cause the user HAS authorized my app (That user also happens to be me and I checked all the permissions under apps, they're fine).

Any suggestions would be greatly appreciated cause I don't know where to look anymore. I know others posted this question before but the answers weren't satisfying. Thanks a lot in advance.

An app isn't allowed to post to a user's wall. You can only post to the wall as the user or as a different user (ie user-to-user). If you want to notify the user of something, you should use the app-to-user Requests API instead.

I couldn't figure out what caused the error. I tried a multitude of angles. In some cases I did manage to post something to the wall because the api returned an ID for the post which I could enter into the the browser to view the post (www.facebook.com/{the-id-of-the-post}).

The strange thing is however, that this post didn't appear on the timeline but on a separate page. This page didn't have the user-profile at the top as is the case with a normal Facebook page. It also had a storyID parameter in the querystring. I couldn't figure out on what page I was and why it didn't just appear on the timeline.

The Facebook-page I was trying to post to was a Company-page. But it wasn't attached to a 'normal' Facebook-page (of a person) as usually is the case. Eventually I did manage to post to the page of a page belonging the a 'normal' facebookpage. So in most cases my code works now. Rest to say that there's still much to improve in the Facebook SDK, it's documentation and that of http://developers.facebook.com . It's not very clear how to perform certain operations. I spent a lot of time once on a WP7 app for a Facebook-feature and now I spent at least 4 days to get this to work for this website. I've decided to write my own SDK and expand it in the future.

Thanks to everyone for your time and help. Stackoverflow rocks!

If the feed you want to post is from the same user who has granted permissions you can put me instead of {the-id-of-the-facebook-user} . I just tried this and it worked:

$facebook->api(
    '/me/feed/',
    'post',
    array(
    'message' => "my message"
));

No need to post access_token. And the permissions the user gave were only publish_actions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM