张贴在墙上使用Facebook图

问题描述:

我想发布在墙上使用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

您应该使用后,如:

 
$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

样品使用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); 
    } 
}); 

希望它能帮助!

干杯!