Mark Henry
Mark Henry

Reputation: 2699

Facebook API Graph and uploading photos

I have a photo upload function for Facebook on my website. See code below.

Once I upload a photo I see a page on Facebook with a result like this:

{
   "id": "3701830342510",
   "post_id": "1177996068_3701808141955"
}

What I want is that the uploader will be transferred to the photo album.

 <?php
       $app_id = "233929";
       $app_secret = "9f3fa8e1e0be4254e0";
       $post_login_url = "http://";
       $album_name = 'My photos';
       $album_description = 'Photos submitted by the members of ';

       $code = $_REQUEST["code"];

       //Obtain the access_token with publish_stream permission 
       if(empty($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'];

         // Get the new album ID
         $album_id = 3597407572006;

         //Show photo upload form and post to the Graph URL
         $graph_url = "https://graph.facebook.com/". $album_id
           . "/photos?access_token=" . $access_token;
         echo '<form enctype="multipart/form-data" action="'
         .$graph_url. ' "method="POST">';
         echo 'Adding photo to : ' . $album_name .'<br/><br/>';
         echo 'Please choose a photo: ';
         echo '<input name="source" type="file"><br/><br/>';
         echo 'Say something about this photo: ';
         echo '<input name="message" type="text"
            value=""><br/><br/>';
         echo '<input type="submit" value="Upload photo" /><br/>';
         echo '</form>';
      }
 ?>

Upvotes: 0

Views: 912

Answers (1)

Nitzan Tomer
Nitzan Tomer

Reputation: 164139

That code, which I suspect you took from the official blog post How-To: Use the Graph API to Upload Photos to a user’s profile uses the facebook graph api url for the form action, and because of that you see that page when the pic is uploaded. You can't control that.

What you can do is use a url of your own as the form action, and then with php upload the pic to facebook and redirect the user where ever you want to. Something like: Facebook: php upload photo and post on wall

Upvotes: 1

Related Questions