简体   繁体   English

将图像和文本链接发布到Facebook墙上

[英]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. 我试图复制功能,在Facebook墙上分享一个类似于该网站的故事。

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. 当您点击共享时,它应该要求您对Facebook进行身份验证,如果您已经过身份验证,则应该向您显示要发布到Facebook的故事。

I got the authentication part to work using the JavaScript SDK . 我使用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);
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM