2011-05-09 149 views
0

我试图复制功能以在Facebook壁上分享一个类似于site的内容的故事。发布带有图片和文字的链接到Facebook墙

当你点击分享时,它应该要求你向Facebook进行身份验证,如果你已经通过身份验证,它应该向你展示发布到Facebook的故事。

我得到认证部分使用JavaScript SDK工作。我不知道如何显示内容贴到墙上。

任何人都可以请提供一个例子。

谢谢!

+0

你说的是安博Twitter的按钮下的 “共享” 按钮? – ifaour 2011-05-09 20:57:45

回答

2
<?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); 
} 
?> 
相关问题