2011-12-19 109 views
0

我想發佈在牆上使用http post請求與給定的網址,但我得到一個方法沒有實現的錯誤。我究竟做錯了什麼?張貼在牆上使用Facebook圖

假設用戶已經授權我的應用程序,並且我有一個具有publish_stream權限的訪問令牌,是否可以創建一個使用facebook圖表發佈到用戶牆上的URL?

這裏是我使用url其中[用戶ID]是用戶ID和[ACCESS_TOKEN]是接入令牌:

https://graph.facebook.com/[userid]/feed?message=I like Cheesy Poofs&picture=http://simplyrecipes.com/photos/cheddar-cheese-puffs-b.jpg&link=alink.com&name=Cheesy Poofs Rule!&caption=Some awesome caption&description=cool description bruh&access_token=[access_token] 

編輯 在上面的鏈接我缺失「方法=交」。我現在從以下網址獲取ID。

https://graph.facebook.com/[userid]/feed?method=post&message=I like Cheesy Poofs&picture=http://simplyrecipes.com/photos/cheddar-cheese-puffs-b.jpg&link=alink.com&name=Cheesy Poofs Rule!&caption=Some awesome caption&description=cool description bruh&access_token=[access_token] 
+0

你應該做一個實際的HTTP POST請求,而不僅僅是添加method = post到你的GET請求。這就是說,我不知道他們爲什麼會在這種情況下給你一個ID。 – 2011-12-19 04:58:34

+0

我應該澄清一點,我在C#中使用WebRequest來發出實際的POST請求。該帖子現在顯示在我的測試業務頁面上。 – imnotsean 2011-12-19 05:27:02

回答

0

您應該使用後,如:

 
$update = $facebook->api('/[userid]/feed', 'post', 
array('message'=> 'your message here', 
'picture' => 'your picture link', 
'link' => 'your link here')); 
+0

我正在爲C#中的桌面應用程序編寫一個簡單的插件,它將在商業頁面的牆上創建一個帖子。由於這相對簡單,我不認爲我需要使用Facebook C#SDK。 – imnotsean 2011-12-19 04:26:39

0

樣品使用PHP ICM簽名的請求:

<?php 

$signedRequestObject = parse_signed_request($_POST["signed_request"],YOUR_APPLICATION_SECRET); 

if ($signedRequestObject["oauth_token"]){ 
    // there is no token, something went wrong 
    exit; 
} 

$token = $signedRequestObject["oauth_token"]; 

$data = array(
    "message" => "happy joy joy message", 
    "link" => "www.myjoyfullsite.com", 
    "access_token" => $token, 
    "picture" => "www.myjoyfullsite.com/avatar.jpg", 
    "name"=> "funky title", 
    "caption"=> "awesome caption", 
    "description"=> "useful description" 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/".$id."/feed"); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
$op = curl_exec($ch); 
if (!$op){ 
    echo "Curl Error : ".curl_error($ch); 
    curl_close($ch); 
    exit; 
} 

curl_close($ch); 
$res = get_object_vars(json_decode((string)$op)); 
print_r($res); 

//used functions 
function parse_signed_request($signed_request, $secret) { 
    list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
    $sig = $this->base64_url_decode($encoded_sig); 
    $data = json_decode($this->base64_url_decode($payload), true); 
    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') { 
    echo 'Unknown algorithm. Expected HMAC-SHA256 : '; 
    return false; 
    } 
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); 
    if ($sig !== $expected_sig) { 
    echo = 'Bad Signed JSON signature!'; 
    return false; 
    } 
    return $data; 
} 

function base64_url_decode($input) { 
    return base64_decode(strtr($input, '-_', '+/')); 
} 

?> 

樣品JS:

var body = 'Reading JS SDK documentation'; 
FB.api('/me/feed', 'post', { message: body }, function(response) { 
    if (!response || response.error) { 
    alert('Error occured'); 
    } else { 
    alert('Post ID: ' + response.id); 
    } 
}); 

希望它能幫助!

乾杯!