Facebook - 将故事发布到用户墙 [英] Facebook- Publishing a story to user's wall

查看:82
本文介绍了Facebook - 将故事发布到用户墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook-php-sdk,我的要求是将故事发布到用户的墙上。我的应用程序在注册/登录时请求用户publish_stream权限。在用户允许并登录后,不知何故,我无法在Facebook上发布用户在我的应用程序中创建的新评论。这是我得到的错误:

I am using facebook-php-sdk and my requirement is to post a story to the user's wall. My app requests the user for 'publish_stream' permission at the time of signup/login. After user has allowed the permission and logged in, somehow I am not able to publish to facebook wall a new comment created by the user on my app. This is the error I get:

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墙上,只需使用正确的参数调用函数

You can use the following code to post into facebook wall , just call the function with proper arguments

尝试此,

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







?>

这篇关于Facebook - 将故事发布到用户墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆