
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 1.47 KB | hits: 14 | expires: Never
PHP: How to post an uploaded photo to wall?
$post = $facebook->api('/me/feed', 'POST', array(...));
<?php
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$post_login_url = "POST_AUTH_REDIRECT_URL";
$photo_id = "PHOTO_ID";
$wall_message = "MESSAGE_FOR_POST";
$wall_link = "LINK_TO_POST";
$user_id = "USER_ID";
$code = $_REQUEST["code"];
// Obtain the access_token with publish_stream permission
if (!$code) {
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url
. "'</script>");
} else {
$token_url="https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// POST to Graph API feed endpoint, which is the user's Wall
$graph_url= "https://graph.facebook.com/" . $user_id . "/feed?"
. "message=" . urlencode($wall_message)
. "&link=" . urlencode($wall_link)
. "&object_attachment=" . $photo_id
. "&method=POST"
. "&access_token=" .$access_token;
echo '<html><body>';
echo file_get_contents($graph_url);
echo '</body></html>';
}
?>
link