【问题标题】:Facebook- Publishing a story to user's wallFacebook-将故事发布到用户的墙上
【发布时间】:2012-02-16 10:08:16
【问题描述】:

我正在使用 facebook-php-sdk,我的要求是将故事发布到用户的墙上。我的应用在注册/登录时向用户请求“publish_stream”权限。用户允许并登录后,不知何故我无法将用户在我的应用程序上创建的新评论发布到 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>';
            }

请分享你的想法

【问题讨论】:

  • 您是在 Facebook 应用程序还是在外部网站中运行此代码?在第一种情况下,尝试删除 api-method-call 中的访问令牌。
  • 您使用的是 Facebook PHP SDK 第 3 版吗?
  • @Blauesocke:我在外部网站上使用它。我尝试在 api 方法调用中删除访问令牌,但同样的问题仍然存在。
  • @fire: 是的,我正在使用版本 3 的 sdk

标签: php facebook facebook-graph-api facebook-php-sdk


【解决方案1】:

您可以使用以下代码发布到 facebook wall ,只需使用适当的参数调用函数

试试这个,

<?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
}







?>

【讨论】:

    【解决方案2】:

    通过https://developers.facebook.com/tools/explorer/再次安装应用程序 选择您的应用并单击获取访问令牌 如果您仍然有问题,请转到您的开发人员仪表板 https://developers.facebook.com/apps 单击编辑设置并检查您设置的 URL 是否正确 在站点 URL:字段中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      相关资源
      最近更新 更多