开发者

Update Facebook wall with PHP

I have a blog system where I want the user to be able to post on there Facebook wall without them having to login to Facebook. I would like it to happen through the PHP SDK delivered by Facebook.

This is the permissions I have given the Facebook application i created:

https://www.facebook.com/dialog/oauth?client_id=xxxxxxxx&redirect_uri=http://www.mydomain.com/facebook/index/&scope=offline_access,publi开发者_开发问答sh_stream,read_stream,manage_pages

Just to clarify the permissions: offline_access,publish_stream,read_stream,manage_pages

Below codes only works if the user is logged in. else I get this error:

FacebookApiException [ 0 ]: An active access token must be used to query information about the current user.

public function facebook()
{
    require_once('facebook/php-sdk-3.0.0/src/facebook');

    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId' => 'xxxxxxxxxxxxx',
      'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
      'cookie' => true,
    ));

    $attachment = array(
        'access_token' => $facebook->getAccessToken(),
        'message' => 'this is my message',
        'name' => 'This is my demo Facebook application!',
        'caption' => "Caption of the Post",
        'link' => 'http://www.google.com',
        'description' => 'Test of application PHP',
        'picture' => 'http://www.lalibre.be/img/logoLaLibre.gif',
        'actions' => array(array(
                                'name' => 'Get Search',
                                'link' => 'http://www.google.com')
                            )
    );

    $result = $facebook->api('/me/feed/','post',$attachment);

    print_r($facebook->getAccessToken());
}


In order to post to someone's wall your application must have wall post permissions for that user. In order to get those permissions the user must login to facebook and grant you access.

For more info: http://developers.facebook.com/docs/authentication/


Also, you need "offline_access" if you want to post when's the user is not logged in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜