Publish to Facebook Stream via PHP using Graph API
Posted
by
Liquid
on Stack Overflow
See other posts from Stack Overflow
or by Liquid
Published on 2010-10-20T20:48:47Z
Indexed on
2010/12/21
6:54 UTC
Read the original article
Hit count: 266
I'm trying to post a message to a user's wall using the new graph API and PHP. Connection seems to work fine, but no post appears. I'm not sure how to set up the posting code correctly. Please help me out. Sorry for the broken-looking code, for some reason StackOverflow didn't want to close it all in the code block.
Below is my full code. Am I missing an extender permission requests, or is that taken care in this code:
PHP Code
<?php
include_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'cookie' => true
));
$session = $facebook->getSession();
if (!$session) {
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
} else {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$updated = date("l, F j, Y", strtotime($me['updated_time']));
echo "Hello " . $me['name'] . "<br />";
echo "You last updated your profile on " . $updated;
$connectUrl = $facebook->getUrl(
'www',
'login.php',
array_merge(array(
'api_key' => $facebook->getAppId(),
'cancel_url' => 'http://www.test.com',
'req_perms' => 'publish_stream',
'display' => 'page',
'fbconnect' => 1,
'next' => 'http://www.test.com',
'return_session' => 1,
'session_version' => 3,
'v' => '1.0',
), $params)
);
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $facebook->access_token, 'message' => 'Playing around with FB Graph..')
);
} catch (FacebookApiException $e) {
echo "Error:" . print_r($e, true);
}
}
?>
© Stack Overflow or respective owner