Post on a wall using Facebook graph

I am trying to post on a wall using an http post request with the given url but I'm getting a method not implemented error. What am I doing wrong?

Assuming the user has already authorized my app and I have an access token with publish_stream permissions, is it possible to create a URL that will post to the users wall using the facebook graph?

Here is the url I am using where [userid] is the user id and [access_Token] is the 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]

Edit In the link above I was missing "method=post". I now get an ID back from the following URL.

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]

Answers


You should be using post, like:

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

Sample using php icm signed request:

<?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, '-_', '+/'));
}

?>

Sample 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);
  }
});

Hope it helps!

Cheers!


Need Your Help

setting language in a Locale

java runtime locale

I would like to know why the following compiles:

How to change email account on Concent screen of Google Cloud Console?

java google-app-engine google-plus google-cloud-console

I am stuck. I have created this app for some time already. At that point I just used my account. Now I'd like present a user with a different email that corresponds to system support email. Is ther...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.