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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:28:28+00:00 2026-05-23T13:28:28+00:00

First off let me start by saying I am using CodeIgniter and the Facebook

  • 0

First off let me start by saying I am using CodeIgniter and the Facebook Class Elliot Haughin created. http://www.haughin.com/code/facebook/ Which I have that working find all all is well. However when I was testing my code with various FB accounts I stumbled across an issue I’d like to assess but my attempts have failed. I have googled around and hit up other forums and I consistently come up with the answers I originally came up with. Something that should by all means work but doesn’t seem to in this case..

Now that I have said that, my issue is.. The object that FB is passing back doesn’t always have a particular entry in it. For the sake of this example Ill say the username..

Heres an example of the Data returned with a username:

facebookResponse Object
(
    [__construct:private] => 
    [__resp] => stdClass Object
        (
            [data] => stdClass Object
                (
                    [id] => 0000000000000
                    [name] => Random.User
                    [first_name] => Random
                    [middle_name] => ...
                    [last_name] => User
                    [link] => http://www.facebook.com/profile.php?id=000000000
                    [birthday] => 11/26/1980
                    [gender] => male
                    [timezone] => -4
                    [locale] => en_US
                    [verified] => 1
                    [updated_time] => 2011-05-30T19:24:53+0000
                )

Here is an example without a username:

facebookResponse Object
(
    [__construct:private] => 
    [__resp] => stdClass Object
        (
            [data] => stdClass Object
                (
                    [id] => 000000000000000000000
                    [name] => Random User
                    [first_name] => Random
                    [last_name] => User
                    [link] => http://www.facebook.com/Random.User
                    [username] => Random.User
                    [birthday] => 11/10/1985
                    [hometown] => stdClass Object
                        (
                            [id] => 000000000000000
                            [name] => Coventry, Connecticut
                        )

                    [location] => stdClass Object
                        (
                            [id] => 00000000000000
                            [name] => San Jose, California
                        )

my last failed attempt at trying to trouble shoot this goes something like..

        $fb_result = $this->facebook->call('get', 'me', array('metadata' => 1));
        $fbFirstName = $fb_result->first_name;
        $fbLastName = $fb_result->last_name;
        $fbUserName = $fb_result->username;
        $fbUserId = $fb_result->id;
        $fbHomeTown = $fb_result->hometown->name;
        $fbLocation = $fb_result->location->name;
        echo "<strong>First Name: </strong>"; if((isset($fbFirstName))AND(!empty($fbFirstName))AND(trim($fbFirstName) !== "")){echo $fb_result->first_name ."<br />"; }else{ echo "Not found.<br />"; }
        echo "<strong>Last Name: </strong>"; if((isset($fbLastName))AND(!empty($fbLastName))AND(trim($fbLastName) !== "")){echo $fb_result->last_name."<br />"; }else{ echo "Not found.<br />"; }
        echo "<strong>Username: </strong>"; if((isset($fbUserName))AND(!empty($fbUserName))AND(trim($fbUserName) !== "")){echo $fb_result->username."<br />"; }else{ echo "Not found.<br />"; }
        echo "<strong>User FB ID: </strong>"; if((isset($fbUserId))AND(!empty($fbUserId))AND(trim($fbUserId) !== "")){echo $fb_result->id."<br />"; }else{ echo "Not found.<br />"; }   
        echo "<strong>Location hometown: </strong>"; if((isset($fbHomeTown))AND(!empty($fbHomeTown))AND(trim($fbHomeTown) !== "")){echo $fb_result->hometown->name."<br />"; }else{ echo "Not found.<br />"; }
        echo "<strong>Location current (manual input): </strong>"; if((isset($fbLocation))AND(!empty($fbLocation))AND(trim($fbLocation) !== "")){echo $fb_result->location->name."<br />"; }else{ echo "Not found.<br />"; }

Which doing it where I am defining it as a variable first then checking it with if-else now is working however. I am now getting “Trying to get property of non-object” for an error. Which means I suppose that since its not there and I am trying to set it as a variable regardless it kicks back an error for it. I have spent the better part of the day and yesterday trying to resolve this and I have to say I am stuck. The php error type is nothing more then a mere “Notice” but I don’t generally like to leave my code in a status that will kick even so much as an error like that back.. That said I am lost..

  • 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-23T13:28:28+00:00Added an answer on May 23, 2026 at 1:28 pm

    You don’t say, but this sounds like the error is given for the lines like

    $fbHomeTown = $fb_result->hometown->name;
    

    when e.g. the hometown property does not exist.

    The way to prevent this notice (and you should definitely strive for completely error-free code) is to do something like this:

    $fbHomeTown = isset($fb_result->hometown->name) ? trim($fb_result->hometown->name) : null;
    

    This sets your temporary variable to a known safe value (either the trimmed value or null). You can then check explicitly for the case where there was no value to begin with by doing

    if($fbHomeTown === null) ...  // 3 equal signs
    

    However, in lots of cases (including yours) you would not even need to distinguish between the “did not exist” and “it’s an empty string” and you would be able to easily complete the processing with something like

    echo "<strong>First Name: </strong>".
         (empty($fbFirstName) ? "Not found.<br />" : $fbFirstName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, let me start by saying that I am totally new to working
First let me start off by saying I do not believe I am leaking,
First off, let me start by saying, I know this exact question has been
Let me start off by saying that this is my first real Cocoa app.
First off, let me start off that I am not a .net developer. The
First let me start of saying I know absolutely nothing about c++ and I
Preface Let me start off by saying that I'm a relatively new programmer and
Let me start off by saying that I am completely new with WPF (this
Let's start off with some code: class Super { protected static $color; public static
First off, let me preface this question by saying that my professor is firmly

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.