Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 1.47 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP: How to post an uploaded photo to wall?
  2. $post = $facebook->api('/me/feed', 'POST', array(...));
  3.        
  4. <?php
  5.   $app_id = "APP_ID";
  6.   $app_secret = "APP_SECRET";
  7.   $post_login_url = "POST_AUTH_REDIRECT_URL";
  8.   $photo_id = "PHOTO_ID";
  9.   $wall_message = "MESSAGE_FOR_POST";
  10.   $wall_link = "LINK_TO_POST";
  11.   $user_id = "USER_ID";
  12.  
  13.   $code = $_REQUEST["code"];
  14.  
  15.   // Obtain the access_token with publish_stream permission
  16.   if (!$code) {
  17.     $dialog_url= "http://www.facebook.com/dialog/oauth?"
  18.       . "client_id=" .  $app_id
  19.       . "&redirect_uri=" . urlencode( $post_login_url)
  20.       .  "&scope=publish_stream";
  21.     echo("<script>top.location.href='" . $dialog_url
  22.       . "'</script>");
  23.   } else {
  24.     $token_url="https://graph.facebook.com/oauth/access_token?"
  25.       . "client_id=" . $app_id
  26.       . "&redirect_uri=" . urlencode( $post_login_url)
  27.       . "&client_secret=" . $app_secret
  28.       . "&code=" . $code;
  29.     $response = file_get_contents($token_url);
  30.     $params = null;
  31.     parse_str($response, $params);
  32.     $access_token = $params['access_token'];
  33.  
  34.     // POST to Graph API feed endpoint, which is the user's Wall
  35.     $graph_url= "https://graph.facebook.com/" . $user_id . "/feed?"
  36.       . "message=" . urlencode($wall_message)
  37.       . "&link=" . urlencode($wall_link)
  38.       . "&object_attachment=" . $photo_id
  39.       . "&method=POST"
  40.       . "&access_token=" .$access_token;
  41.  
  42.     echo '<html><body>';
  43.     echo file_get_contents($graph_url);
  44.     echo '</body></html>';
  45.   }
  46. ?>
  47.        
  48. link