0

I'm just trying to make PHP Connector to Facebook for posting wall posts on a Page. So i'm not trying to post wall post to profile wall or anything else.

I've read some tutorials and manuals and i decided to use Facebook PHP-SDK (from Naitik Shah) https://github.com/facebook/php-sdk/

I've created Facebook App to post wallposts through it. I received appId and api secret. I've added application permissions to my Page and tried example code

$facebook = new Facebook(array(
    'appId' => 'my app id',
    'secret' => 'my api secret',
    'cookie' => false,
    'domain' => 'domain.com'
));

domain.com => domain from which i'm sending api requests next ->

$facebook->getSession();
$token = $facebook->getAccessToken();
$facebook->api('/123456789/feed', array(
    'access_token' => $token,
    'link' => 'http://www.example.com'
));

So i'm trying to post link on wall of page with id 123456789

The request goes through without warnings/errors but nothing is posted in right place and nothing is returned.

Thanks for any idea about this problem.

Used tutorials:

How do you post to the wall on a facebook page (not profile)
http://blog.theunical.com/facebook-integration/5-steps-to-publish-on-a-facebook-wall-using-php/
http://www.moskjis.com/other-platforms/publish-facebook-page-wall-from-your-site
http://tips4php.net/2010/12/automatic-post-to-facebook-from-php-script/

Community
  • 1
  • 1
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244

2 Answers2

2
$facebook->api('/123456789/feed', 'post', array(
    'access_token' => $token,
    'link' => 'http://www.example.com'
));

Note the 'post' part.

If you look at the source for the API via the link you provided, you'll see:

protected function _graph($path, $method='GET', $params=array()) {
    if (is_array($method) && empty($params)) {
      $params = $method;
      $method = 'GET';
    }

When you don't have 'post' as the second argument and your array as the third, it goes a get

Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • Yes, you're right. Thanks Brian. Now I have to solve "OAuthException: (#200) The user hasn't authorized the application to perform this action" but it is another problem. Thanks anyway :) – Marek Sebera Apr 22 '11 at 14:54
  • @ Marek Sebera , i am having same problem did you found any solution. – Punit Nov 16 '11 at 14:04
1

If you are getting authorisation errors, make sure you have included the following permission:

 publish_stream

https://developers.facebook.com/docs/reference/api/post/

Relaxing In Cyprus
  • 1,976
  • 19
  • 25