2011-04-27 101 views
0

我是新的facebook應用程序開發,我被卡在如何發佈到Facebook。 我讀過教程,並根據他們做。卡在張貼到臉書

下面是代碼:

<?php 

require 'facebook.php'; 
// Create our Application instance (replace this with your appId and secret). 

Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; 
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2; 

$facebook = new Facebook(array(
    'appId' => 'xxx', 
    'secret' => 'xxx', 
    'cookie' => true, 
)); 


//Request params 
if(!($_GET['code'])) { 
    header("Location:https://www.facebook.com/dialog/oauth?client_id=xxx&redirect_uri=" . urlencode("http://localhost/facebook/examples/") . "&scope=publish_stream"); 
    //header("Location:http://www.google.com"); 
    exit; 
} 

$token = $_GET['code']; 
echo "token " . $token 


$status = $facebook->api('/me/feed', 'POST', array('message' => 'This post came from my app.', 'access_token' => $token)); 
var_dump($status); 

?> 

結果:
致命錯誤:未捕獲OAuthException:用C拋出爲簽名:\瓦帕\ WWW \實\例子\ facebook.php上線543

我錯過了什麼嗎?

回答

0

好吧,您正在使用原始的OAuth登錄,並在同一時間使用Facebook的PHP SDK。 不要那樣做,如果你正在使用SDK我們所有的方式:

 
<?php 

require 'facebook.php'; 
// Create our Application instance (replace this with your appId and secret). 

Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false; 
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2; 

$facebook = new Facebook(array(
    'appId' => 'xxx', 
    'secret' => 'xxx', 
    'cookie' => true, 
)); 

if (!$facebook->getSession()) 
{ 
    header('Location: ' . $facebook->getLoginUrl(array('req_perms' => 'publish_stream'))); 
} 
else 
{ 
    $status = $facebook->api('/me/feed', 'POST', array('message' => 'This post came from my app.')); 
    var_dump($status); 
} 

?> 

SDK將處理令牌他自己;)