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 7716751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:42:39+00:00 2026-06-01T02:42:39+00:00

Hello everyone I am a newbie to php and this is my first ever

  • 0

Hello everyone I am a newbie to php and this is my first ever app over php.

I am trying to create a new album through graph api and upload photos to it.

I’ve the following code in place, problem is when after creating an album facebook graph api returns data that contains the id of the album and that id is later used to upload photos to that album.

In my case I am getting the data but I am unable to read through it, I tried to access it as an object, as an array but none is working.

To check the viability when I tried to print it whole it is giving output like this.
Result: {"data":[{"id":"321215475937088","from":{"name":"Lorem …

I want to know how I can access this id element? whether $result is an array, object or what. I’ve tried every possibility that I could come up with but am not getting the required output.

// 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));
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $graph_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $result = curl_exec($ch);
        curl_close($ch);
        echo "<pre>";
        echo "Result: " . $result; //output of this line is given above
        echo "Result[id]: " . $result[id]; //Notice: Use of undefined constant id - assumed 'id' ...
        echo "Result[data][id]: " . $result[data][id]; //Notice: Use of undefined constant data - assumed 'data'...
//Notice: Use of undefined constant id - assumed 'id'...
//Fatal error: Cannot use string offset as an array in ...
        echo "Result ID: " . $result -> id;
        echo "Data - >ID: " . $data->id;
        echo "Data ID: " . $data[id];
        echo "</pre>";
        // Get the new album ID
        $album_id = $result -> id;
  • 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-06-01T02:42:40+00:00Added an answer on June 1, 2026 at 2:42 am

    You’re getting JSON serialized object.
    You need to deserialize it before use.
    You could do it like this:

    echo "Result: " . $result;
    $result = json_decode($result);
    

    After that you can access properties of the object:

    echo "Result ID: " . $result->data[0]->id;
    

    *Please note that data in your response string is an array which contains objects

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

Sidebar

Related Questions

hello everyone im trying to create this tweak that copies a file from one
Hello everyone this is my first post on stack overflow.com I am trying to
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello everyone i am trying to format the input number range with php number_format
Hello everyone I'm currently trying to create a deferred renderer for my graphics engine
Hello everyone, I have been banging my head really hard trying to solve this
Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script
Hello everyone I'm trying to work with jboss messaging, does anyone knows the default
Hello everyone I'm trying to improve my Java skills by solving some problems from
Hello everyone I am new to blackberry and I want a textfield that scroll

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.