简体   繁体   中英

Posting a link with image and text to Facebook wall

I am trying to replicate the functionality to share a story on a Facebook wall similar to what this site has.

When you click on the share it should ask you to authenticate to facebook, if you are already authenticated it should show you the story to post to facebook.

I got the authentication part to work using the JavaScript SDK . I am not sure how to show the content to post to the wall.

Could anyone please provide an example.

Thanks!

<?php
# We require the library
require("facebook.php");

# Creating the facebook object
$facebook = new Facebook(array(
    'appId'  => 'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
    'cookie' => true
));

# Let's see if we have an active session
$session = $facebook->getSession();

if(!empty($session)) {
    # Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
    try{
        $uid = $facebook->getUser();

        # let's check if the user has granted access to posting in the wall
        $api_call = array(
            'method' => 'users.hasAppPermission',
            'uid' => $uid,
            'ext_perm' => 'publish_stream'
        );
        $can_post = $facebook->api($api_call);
        if($can_post){
            # post it!
            # $facebook->api('/'.$uid.'/feed', 'post', array('message' => 'Saying hello from my Facebook app!'));

            # using all the arguments
            $facebook->api('/'.$uid.'/feed', 'post', array(
                'message' => 'The message',
                'name' => 'The name',
                'description' => 'The description',
                'caption' => 'The caption',
                'picture' => 'http://i.imgur.com/yx3q2.png',
                'link' => 'http://net.tutsplus.com/'
            ));
            echo 'Posted!';
        } else {
            die('Permissions required!');
        }
    } catch (Exception $e){}
} else {
    # There's no active session, let's generate one
    $login_url = $facebook->getLoginUrl();
    header("Location: ".$login_url);
}
?>

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