首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >在Facebook墙上张贴带有图片和文本的链接

在Facebook墙上张贴带有图片和文本的链接
EN

Stack Overflow用户
提问于 2011-05-09 19:45:01
回答 2查看 1.2K关注 0票数 0

我正在尝试复制在Facebook墙上分享故事的功能,类似于这个site所拥有的功能。

当你点击分享时,它会要求你向facebook认证,如果你已经通过认证,它应该会向你显示要发布到facebook上的故事。

我使用JavaScript SDK 实现了身份验证部分。我不确定如何显示要发布到墙上的内容。

谁能举个例子。

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-09 19:46:17

Stack Overflow用户

发布于 2012-02-22 10:29:53

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?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);
}
?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5941694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文