2012-02-16 141 views
0

我正在使用facebook-php-sdk,我的要求是将故事发布到用户的墙上。我的应用在注册/登录时向用户请求'publish_stream'权限。在用户已经允许并登录之后,以某种方式,我无法将在用户创建的新评论发布到Facebook墙上的应用程序中。这是我的错误:Facebook-向用户墙发布故事

Invalid OAuth access token signature 

这是我做的:

$facebook = new Facebook(array(
           'appId' => "$fb_app_id", 
           'secret' => "$fb_secret", 
           'cookie' => true 
         )); 
try { 
      $fb_user_id = $facebook->getUser(); 
      $access_token = $facebook->getAccessToken(); 
      $facebook->api("/me/feed", 'post', array(
             'access_token' => $access_token, 
             'message' => 'I love SO', 
             'link' => 'http://mydomain.com', 
             'picture' => 'http://thinkdiff.net/ithinkdiff.png', 
             'name' => 'iOS Apps & Games', 
             'description'=> 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!' 
            ) 
          ); 
      } catch (FacebookApiException $e) { 
       echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>'; 
      } 

分享您的想法,请

+0

是你在facebook应用程序或外部网站中运行此代码?在第一种情况下,尝试删除api-method-call中的访问令牌。 – 2012-02-16 10:15:14

+0

您是否使用Facebook PHP SDK的第3版? – fire 2012-02-16 10:15:43

+0

@Blauesocke:我正在外部网站上使用它。我试图在api方法调用中删除访问令牌,但同样的问题依然存在。 – Ninja 2012-02-16 10:25:39

回答

1

您可以使用下面的代码发布到Facebook涂鸦墙,只需调用函数与正确的参数

试试这个,

<?php 


function doWallPost($postName='',$postMessage='',$postLink='',$postCaption='',$postDescription='') 
{ 
$FB_APP_ID='xxxxxxxxxxxxxxxxxxxxxxxx'; 
$FB_APP_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxx'; 

$APP_RETURN_URL=((substr($_SERVER['SERVER_PROTOCOL'],0,4)=="HTTP")?"http://":"https://").$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; 

$code = $_REQUEST["code"]; 

if(empty($code)) 
{ 
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=".$FB_APP_ID."&redirect_uri=".$APP_RETURN_URL."&scope=publish_stream";     
    header("Location:$dialog_url"); 
} 

$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$FB_APP_ID."&redirect_uri=".urlencode($APP_RETURN_URL)."&client_secret=".$FB_APP_SECRET."&code=".$code; 
$access_token = file_get_contents($token_url); 

$param1=explode("&",$access_token); 
$param2=explode("=",$param1[0]); 
$FB_ACCESS_TOKEN=$param2[1]; 


$url = "https://graph.facebook.com/me/feed"; 
$attachment = array( 'access_token' => $FB_ACCESS_TOKEN,       
       'name'   => $postName, 
       'link'   => $postLink, 
       'description' => $postDescription, 
       'message'  => $postMessage, 
       'caption'  => $postCaption, 
      ); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,2); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); 
$result=curl_exec($ch); 
header('Content-type:text/html'); 
curl_close($ch); 

return $result 
} 







?> 
+0

不要忘记在上面的代码中给你的appid和你的秘密 – 2012-02-16 11:12:36

+0

@Ninja做一些upvote,如果这为你工作 – 2012-02-17 06:50:01