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

  • SEARCH
  • Home
  • 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 870997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:34:15+00:00 2026-05-15T10:34:15+00:00

I am trying to upload a image to a gallery on a facebook fan

  • 0

I am trying to upload a image to a gallery on a facebook fan page, here is my code thus far,

$ch = curl_init();

        $data = array('type' => 'client_cred', 'client_id' => 'app_id','client_secret'=>'secret_key',' redirect_uri'=>'http://apps.facebook.com/my-application/'); // your connect url here

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        $rs = curl_exec($ch);
        curl_close($ch);

        $ch = curl_init();
        $data = explode("=",$rs);
        $token = $data[1];

        $album_id = '1234';
        $file= 'http://my.website.com/my-application/sketch.jpg';
        $data = array(basename($file) => "@".realpath($file),
        //filename, where $row['file_location'] is a file hosted on my server
            "caption" => "test",
            "aid" => $album_id, //valid aid, as demonstrated above
            "access_token" => $token
        );

        $ch2 = curl_init();
        $url = "https://graph.facebook.com/".$album_id."/photos";
        curl_setopt($ch2, CURLOPT_URL, $url);
        curl_setopt($ch2, CURLOPT_HEADER, false);
        curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch2, CURLOPT_RETURNTRANSFER, false);
        curl_setopt($ch2, CURLOPT_POST, true);
        curl_setopt($ch2, CURLOPT_POSTFIELDS, $data);
        $op = curl_exec($ch2);

When I echo $token, I seem to be getting the token, but when I run the script, I get this error, {“error”:{“type”:”OAuthAccessTokenException”,”message”:”An access token is required to request this resource.”} , I have NO idea why it is doing this!

Basically what I am doing in that code is getting the access token with curl, and then, uploading the photo to my album also via curl, but I keep getting that error!

Any help would be appreciated, 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-15T10:34:16+00:00Added an answer on May 15, 2026 at 10:34 am

    Ok, got it working, here is the code, assuming that you have a valid session going.

        $token = $session['access_token'];
    
        //upload photo
        $file= 'photo.jpg';
        $args = array(
        'message' => 'Photo from application',
        );
        $args[basename($file)] = '@' . realpath($file);
    
        $ch = curl_init();
        $url = 'https://graph.facebook.com/me/photos?access_token='.$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);
    

    This will upload the specified image to the session holders gallery, it will create a album if there is not one present, also you can access the token via the session array as demonstrated above.
    Hope this helps someone out.

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

Sidebar

Related Questions

i am trying to upload an image from a jsp page using servlet. but
Im struggling here for a lot, Im trying to upload an image from iphone
I'm trying to upload image to Amazon S3 with this Ruby code: require 'net/http/post/multipart'
I have created a custom post type with an image gallery upload. Now I
i am trying to upload a image to server from iPhone application PHP code
I am trying to upload an image from the Androids photo gallery to a
I am trying to upload an image through my application with Facebook Graph API
I'm trying to upload an image file from an android device to my drupal
I am trying to upload an image to the server. I hava a form
I am trying to upload a image which i am clicking with the help

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.