Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7559733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:42:36+00:00 2026-05-30T12:42:36+00:00

Hello I am new to facebook app development and working over my first app.

  • 0

Hello I am new to facebook app development and working over my first app.
My app is basically supposed to post a new photo over the users publish stream and for that purpose the first thing I’ve is image creation process which is in this way:

<?php
        //Image Processing:

        $brandName = "nweing";
        $imageUrl = "newimage.jpg";
        $imageId = imagecreatefromjpeg($imageUrl);

        $xCord = 5;
        $yCord = 10;
        $fontUrl = "GOTHIC.TTF";

        $imageText = "Image Text";
        echo $imageUrl . $imageId;
        $imageColor = imagecolorallocate($imageId, 255, 255, 255);
        $imageFont = 1;
        $fontSize = 16;

        //imagestring($imageUrl, $imageFont, $xCord, $yCord, $imageText, $imageColor);
        imagefttext($imageId, $fontSize, 0, $xCord, $yCord, $imageColor, $fontUrl, $imageText);

        header("Content-type: image/png");
        imagepng($imageId);
        imagedestroy($imageId);
        ?>

Then I’ve configured the code as directed here to post photos with respective app values:

<?php

   $app_id = "366325366724856";
   $app_secret = "b14ac6d2b7345db259599b06983e881";
   $post_login_url = "YOUR_POST-LOGIN_URL";
   $album_name = 'My Album';
   $album_description = 'My Album Description';

   $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'];

     // Create a new album
     $graph_url = "https://graph.facebook.com/me/albums?"
     . "access_token=". $access_token;

     $postdata = http_build_query(
     array(
      'name' => $album_name,
      'message' => $album_description
        )
      );
     $opts = array('http' =>
     array(
      'method'=> 'POST',
      'header'=>
        'Content-type: application/x-www-form-urlencoded',
      'content' => $postdata
      )
     );
     $context  = stream_context_create($opts);
     $result = json_decode(file_get_contents($graph_url, false, 
       $context));

     // Get the new album ID
     $album_id = $result->id;

     //Show photo upload form and post to the Graph URL
     $graph_url = "https://graph.facebook.com/". $album_id
       . "/photos?access_token=" . $access_token;
     echo '<html><body>';
     echo '<form enctype="multipart/form-data" action="'
     .$graph_url. ' "method="POST">';
     echo 'Adding photo to album: ' . $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" /><br/>';
     echo '</form>';
     echo '</body></html>';
  } ?>

But his code is about asking user to upload an image to through html form but I want the image that I made in the earlier code to get published.
So my question how I can pass that image to Graph API endpoint to be published in user stream.

Thank-you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:42:38+00:00Added an answer on May 30, 2026 at 12:42 pm

    You could save the image to a temporary file and then use the photo upload code from this answer

        $app_id = "366325366724856";
        $app_secret = "b14ac6d2b7345db259599b06983e881";
        $post_login_url = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        $album_name = 'My Album';
        $album_description = 'My Album Description';
    
        $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>");
            exit;
        }
    
        // Make sure you have read & write access to this folder
        $tmpfile = "/tmp/" . md5(rand()) . ".png";
    
        $brandName = "nweing";
        $imageUrl = "newimage.jpg";
        $imageId = imagecreatefromjpeg($imageUrl);
    
        $xCord = 5;
        $yCord = 10;
        $fontUrl = "GOTHIC.TTF";
    
        $imageText = "Image Text";
        $imageColor = imagecolorallocate($imageId, 255, 255, 255);
        $imageFont = 1;
        $fontSize = 16;
    
        imagefttext($imageId, $fontSize, 0, $xCord, $yCord, $imageColor, $fontUrl, $imageText);
    
        imagepng($imageId,$tmpfile);
        imagedestroy($imageId);
    
        $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'];
    
        // Create a new album
        $graph_url = "https://graph.facebook.com/me/albums?access_token=". $access_token;
    
        $postdata = http_build_query(array('name'=>$album_name,'message'=>$album_description));
        $opts = array('http'=>array('method'=>'POST','header'=>'Content-type: application/x-www-form-urlencoded','content' => $postdata));
        $context  = stream_context_create($opts);
        $result = json_decode(file_get_contents($graph_url, false, $context));
    
        // Get the new album ID
        $album_id = $result->id;
    
        //upload photo
        $args = array('message'=>'Photo caption',);
        $args[basename($tmpfile)] = '@' . realpath($tmpfile);
    
        $ch = curl_init();
        $url = 'http://graph.facebook.com/' . $album_id . '/photos?access_token=' . $access_token;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
        $data = curl_exec($ch);
    
        unlink($tmpfile);
    
        //returns the photo id
        print_r(json_decode($data,true));
    ?>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I am trying out my first Facebook app, a hello worldesque construction.
Hello guys i am new about this implementing facebook into my app.I check developer's
Hello I am new to iPhone development and I am making an app which
Hello Guys I am working on WPF app and I want to Unlike the
Hello im new to programming, im trying to construct my first simple application, im
I am working on my second Facebook App and seem to have run into
Hello I am really new on Facebook API. I found this url ( https://graph.facebook.com/page_id_goes_here/insights/page_fans
Possible Duplicate: What's the shebang (#!) in Facebook and new Twitter URLs for? Hello,
class Hello @hello = hello def display puts @hello end end h = Hello.new
hello I'm new to PHP programming and I migrated from ASP .net to PHP..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.