Viewed   256 times

I'm storing facebook userid's and access tokens. Can i post to a selected user's wall with this information? The following code is found here: I'm just not sure how to run it with php.

curl -F 'access_token=$accessToken' 
     -F 'message=Check out this funny article' 
     -F 'link='$facebookid/feed


$attachment =  array(
'access_token' => $token,
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);
Wednesday, November 23, 2022

You could consider using the FB javascript SDK for doing the logout and then you do not need to redirect (it is also possible to register a javascript callback and use window.location to do that):

FB.logout(function(response) { // user is now logged out window.location = "xxxx"; });

If you want to use the php sdk, you can pass in a "next" parameter, with the page you want to direcrect to: $location = (string) html_entity_decode($facebook->getLogoutUrl(array('next' => '')));

Wednesday, August 3, 2022

I had the same issue using user_token to add event and cover into page. My workaround is to get page_token using that user_token, and then create event and cover using page_token.

$fb->setAccessToken($user_token); //set your user token

$result = $fb->api($page_id.'?fields=access_token', 'get');

if(isset($result["access_token"])) //this will be set if your user has a permission on the page.
    $page_token = $result["access_token"]; 

//create event add cover as before
Sunday, September 4, 2022

It's not possible to post on the user's wall as app or page. And even if it's possible, it's not recommended!

Your best bet if you want to notify your fans about something is to post on your page's wall (as your page) where this post will appear in your fans news feed.

Also this can be done for your website fans (Likers):

Friday, October 7, 2022

Finally, after a lot of tests, it worked, without the PHP SDK. This is the step by step guide:

1. Get permissions and the page token

Go to and select your app from the first drop down menu, in the left.

Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.

You may be asked in this step to grant permissions to your app to access to your Facebook account, accept.

Next, click at the end of the text field next to the "GET" drop down, and replace the numbers for: me/accounts, and click in the blue button next to this text field.

You'll get the tokens for all your pages, including your app page. Find your page name in the list, will look like this: "name": "Your page name"

When you located your page, copy the access token for the page (will be really long), that can look like this: "access_token": "XXXXXXXX". Also copy the id of the page: "id": "XXXXX".

That's all for this step, we can start coding now.

2. Post to your page wall via PHP

First, for this script, you'll need a server supporting curl.

We start the PHP document defining the page access token and the page id that we've get in the 1st step:

$page_access_token = 'XXXXXXX';
$page_id = 'YYYYYYYY';

After that, we create an array with the info to post to our page wall:

$data['picture'] = "";
$data['link'] = "";
$data['message'] = "Your message";
$data['caption'] = "Caption";
$data['description'] = "Description";

You can of course, use any other post parameter described in and if you don't need one or many of the parameters above you can simply delete it.

Ok, At this point we add to the array the access token:

$data['access_token'] = $page_access_token;

And we set our post URL, to post in our page:

$post_url = ''.$page_id.'/feed';

And the last step, we'll use a curl to post our message in our page wall:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);

After that, we can save our PHP document, and try to execute it. The post may appear in our Facebook page.

Hope this code helps to other people with the same problem!

Thursday, August 25, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :