简体   繁体   中英

Post in a message on the wall using Graph API?

I am learning Facebook app development and I want my app to post a simple message on the wall of the user.

How do I do it using the graph API?

I am using servlets for the development of app.

Firstly you need to get the access_token of the user (after it makes a login) with 'https://graph.facebook.com/oauth/'.

https://developers.facebook.com/docs/authentication/

Notice that his access_token will be retrieved to your own php or whatelse "&redirect_uri=WWW.YOUR_WEB.PHP" by a $REQUEST['code'] that you'll have to uncode in this way:

$code =  $_REQUEST['code'];

$url = "https://graph.facebook.com/oauth/access_token?";
$url .= "client_id=" . $APP_ID;
$url .= "&client_secret=" . $APP_SECRET;
$url .= "&code=" . $code;
$url .= "&redirect_uri=" . $MY_URL;

$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
$response = curl_exec($c);
curl_close($c);

$response = explode("&", $response);
foreach($response as $key => $value)
{
$pair = explode("=", $value);
$response[$pair[0]] = $pair[1];
unset($response[$key]);
}

$access_token = $response['access_token'];
$expires = $response['expires'];

Later to post on a wall you need to call an url in this way:

_url = "https://graph.facebook.com/" + user_id + "/feed?message=MSG_STRING"
_url += "&access_token=" + access_token;
_url += "&name=NAME_STRING";
_url += "&link=LINK_URL";
_url += "&description=DESCRIPTION_STRING";
_url += "&method=post";

https://developers.facebook.com/docs/reference/api/post/

You can use the socialauth library to post a message on FB wall.
http://code.google.com/p/socialauth/

How to post a message on friend's wall, Visit a following link:-
http://code.google.com/p/socialauth/issues/detail?id=233 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM