Marcin Majchrzak
Marcin Majchrzak

Reputation: 682

How to share external links or URLs on Facebook

I need to write application that will be sending links to facebook fanpage wall.
I use a PHP SDK v3. There is a example how to post stuff:

require 'facebook.php';
$facebook = new Facebook(array(
    'appId'  => 'XXXX',
    'secret' => 'YYYYYYYYYY',
    'cookie' => true,
));
$fbsession = $facebook->getSession();

    if ($fbsession) {
       $attachment = array(
          'message' => 'this is my message',
          'name' => 'This is my demo Facebook application!',
          'caption' => "Caption of the Post",
          'link' => 'http://www.lycos.com',
          'description' => 'Test de post depuis application PHP',
          'picture' => 'http://www.lalibre.be/img/logoLaLibre.gif',
          'actions' => array(array('name' => 'Get Search',
          'link' => 'http://www.google.com'))
      );
     $result = $facebook->api('/USER_WALL/feed/','post',$attachment);
  }

and it works fine. The problem is I want to post just a normal facebook-link (with link icon, without application name and with Share button)

something like this:

$result = $facebook->api('/USER_WALL/feed/','link',$attachment);

gives me an error (Fatal error: Uncaught Exception: Unsupported method, link thrown in /home/.../src/base_facebook.php on line 959)

any ideas how to do this? I found two links to FB Documentation:

but I still don't know use this in PHP-SDK v3

Upvotes: 1

Views: 9565

Answers (2)

Marcin Majchrzak
Marcin Majchrzak

Reputation: 682

solved:

    $attachment = array(
        'access_token'=>TOKEN,
        'message'=>'message_here',
        'link' => 'http://www.example.com',
    );
    $result = $facebook->api(
        'me/links',
        'post',
        $attachment
    );

Upvotes: 0

Sujit Agarwal
Sujit Agarwal

Reputation: 12508

Check this example on this website. Its a full implementation of the status update and posting technique on a users wall. LINK TO THE TUTORIAL

EDIT AFTER READING THE COMMENTS

Use the following url to share custom links:

http://www.facebook.com/sharer.php?u=http://www.YourUrlThatYouWantToShare.com

Upvotes: 1

Related Questions