Welcome Guest, Not a member yet? Register   Sign In
Facebook SDK Problem retrieved user data
#1

[eluser]Dynamica Technology[/eluser]
Hi

I create in my website Facebook Login and it's works fine, now I want to retrieved user data with API call method and insert in DB, but when I want retrieved user_birthday or any user Permissions I receive an error:
Quote:Undefined index: user_birthday

Could you help me.
Thanks

This is my model:
Code:
public function __construct()
{
  parent::__construct();
  
  $config = array(
   'appId'  => 'myappid',
   'secret' => 'myidsecret',
   'fileUpload' => true,
      );
  
  $this->load->library('Facebook', $config);

  
  $user = $this->facebook->getUser();

  $profile = null;
  if($user)
  {
   try {

    $profile = $this->facebook->api("/me", 'get');

   } catch (FacebookApiException $e) {
    error_log($e);
       $user = null;
   }  
  }
  
  $fb_data = array(
      'me' => $profile,

      'uid' => $user,
      'loginUrl' => $this->facebook->getLoginUrl(
       array(
        'scope' => 'email,publish_stream,user_about_me,user_checkins,publish_stream,friends_about_me,user_birthday',
                       'redirect_uri' => base_url() . 'index.php/dashboard'
       )
      ),
      'logoutUrl' => $this->facebook->getLogoutUrl(
       array(
                       'next' => base_url()
       )
      ),
     );

  $this->session->set_userdata('fb_data', $fb_data);
  
  $this->db->get('account');
  
    
  $db_data=array(
    'name'=>$fb_data['me']['first_name'],
    'surname'=>$fb_data['me']['last_name'],
    'nickname'=>$fb_data['me']['username'],
    'slug'=>$fb_data['me']['first_name'] .'.' .$fb_data['me']['last_name'],
    'city'=>$fb_data['me']['username'],
    'country'=> 'VUOTO',
    'age'=>$fb_data['me']['user_birthday'],
    'sex'=>$fb_data['me']['gender'],
    'email'=>$fb_data['me']['email'],
    'facebook'=>$fb_data['uid'],
    'avatar'=> 'https://graph.facebook.com/'.$fb_data['uid'],
  );
  
  $this->db->insert('account',$db_data);
}
#2

[eluser]JoostV[/eluser]
It says user_index is not in $fb_data['me']. Did you check if it is?
Code:
echo '<pre>' . print_r($fb_data)'
#3

[eluser]Dynamica Technology[/eluser]
Thanks

I have check and you have right
Code:
user_birthday
is not in
Code:
$fb_data['me']

Now how insert
Code:
user_birthday
in
Code:
$fb_data['me']
?

I put in
Code:
scope
declaration, but not work
#4

[eluser]JoostV[/eluser]
Not sure. It's supposed to be called user_birthday in the scope, which then should be accessible as 'birthday'. https://developers.facebook.com/docs/how...a-ios-sdk/
#5

[eluser]Dynamica Technology[/eluser]
thanks you've right

is requires to put the permissions in scope declaration and after use only 'birthday'

thank
#6

[eluser]Dynamica Technology[/eluser]
Hi JoostV

Working with facebook skd I discovered something strange

I have start this post because I don't for errors of birthday or for other user Permissions.

after your reply I continued too work but I had same problem.

after 3 hour I discovered that the error is not for my wrong code, but because the Facebook Account don't have the relative field.

I'll explain;

I proof the app with my wife account now she has not set her birthday, for this reason I had the error
same problem with bio (user_about_me) she has not set nothing into her About me, in fact after I insert two words in the About me(facebook) the app don't show any error and I retrieved the bio fields.

Now, I want to know.. It's is normal ? and if is normal how bypass this problem, off course not all people insert all info in Facebook Account.

thanks
#7

[eluser]JoostV[/eluser]
Haha, you never know what's normal with Facebook Wink

Anyway, it's best to never trust any incoming data and the same goes for data coming from the Facebook API. Best do something like
Code:
echo !empty($fbdata['birthday']) ? htmlentities($fbdata['birthday']) : 'Unknown';

Or better yet, stick that in a helper function (see https://gist.github.com/4064663)
EDIT fixed a big in this code
Code:
/**
* Return the value for a key in an array or a property in an object.
* @param mixed $haystack
* @param string $needle
* @param mixed $default_value The value if key could not be found.
* @return mixed
*/
function get_key ($haystack, $needle, $default_value = '')
{
if (is_array($haystack)) {
// We have an array. Find the key.
        return isset($haystack[$needle]) ? $haystack[$needle] : $default_value;
    }
    else {
     // If it's not an array oit must be an object
     return isset($haystack->$needle) ? $haystack->$needle : $default_value;
    }
}

// In your view, do stuff like
echo htmlentities(get_key($fbdata, 'birthday'));
#8

[eluser]Dynamica Technology[/eluser]
Thanks

but I can use

Code:
function get_key ($haystack, [quote] $needle, [/quote] $default_value = '')

my Hosting use PHP 5.2

because I don't possible to use strstr with $needle parameter (is add after 5.3.0 version)
#9

[eluser]Dynamica Technology[/eluser]
Code:
Haha, you never know what’s normal with Facebook ;-)

You have right!!!!

but I think that I makes me mad :grrr:

Now explain because

5 hours ago I check my project and I discovered that Facebook login not works

Why, I think, upload the backup and fix the problem.

but nothing has changed.

the problem is that I don't retrieved the Facebook UID, why if I don't change any code?

Why one day works and another day no ?

this is my model:
Code:
$config = array(
  'appId'  => 'XXXX',
  'secret' => 'XXXX',
  'fileUpload' => true,
        );
  
  $this->load->library('Facebook', $config);

  $user = $this->facebook->getUser();

  
  $profile = null;
  if($user)
  {
   try {
         $profile = $this->facebook->api('/me');
    
   } catch (FacebookApiException $e) {
    error_log($e);
       $user = null;
   }  
  }
  
  $fb_scope ='email,
       user_birthday,
       user_about_me,
       user_website,
       user_interests,
       user_checkins,
       publish_stream,
       read_stream,
       read_friendlists
       ';
  
  $fb_redirect = base_url() .'index.php/dashboard/';
  
  $fb_data = array(
      'me' => $profile,
      'uid' => $user,
      'loginUrl' => $this->facebook->getLoginUrl(
          array(
     'scope' => $fb_scope,
                       'redirect_uri' => $fb_redirect,
           )
       ),
    'logoutUrl' => $this->facebook->getLogoutUrl(
       array(
                       'next' => base_url()
     )
       ),
    );

  $this->session->set_userdata('fb_data', $fb_data);
#10

[eluser]Dynamica Technology[/eluser]
I makes me mad

I use my daughter's account and the projects works fine !!!!

but if I use my wife's account not works

Why ?




Theme © iAndrew 2016 - Forum software by © MyBB