使用Facebook图表在墙上发布

时间:2011-12-19 01:20:00

标签: facebook post facebook-graph-api

我正在尝试使用带有给定网址的http发布请求发布在墙上但我得到的方法未实现错误。我做错了什么?

假设用户已经授权我的应用程序并且我有一个具有publish_stream权限的访问令牌,是否可以创建一个使用facebook图表发布到用户墙的URL?

以下是我使用的网址,其中[userid]是用户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]

修改 在上面的链接中我错过了“method = post”。我现在从以下网址获取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]

2 个答案:

答案 0 :(得分:0)

您应该使用帖子,例如:

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

答案 1 :(得分: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);
  }
});

希望它有所帮助!

干杯!