Pergunta

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

This is what I do:

 $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>';
            }

Do share your thoughts please

Foi útil?

Solução

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

Try this ,

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







?>

Outras dicas

install app again through https://developers.facebook.com/tools/explorer/ select your app & click on Get access token if you still have problem go to your developer dashboard https://developers.facebook.com/apps click on Edit settings & check up you set correct URL in Site URL: field

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top