Topic-icon get facebook name and first name for 5.0

Active Subscriptions:

None
13 years 2 months ago #31898 by Ivan
Hi,

I was able to make this call : $fbClient->getUserName in 4.3.3. which is not in 5.0
   function _getUserName($fbUserId)
    {
        $fields = array(0 => 'first_name', 1 => 'last_name', 2 => 'status', 3 => 'email', 4 => 'name');
        return $this->getUserProfile($fbUserId, $fields);
    }

   function getUserProfile($fbUserId, $fields)
    {
        $colFields = implode(",", $fields);
        $fql = "SELECT " . $colFields . " FROM user WHERE uid=" . $fbUserId;
        $params = array(
            'method' => 'fql.query',
            'query' => $fql,
        );
        $profile = $this->rest($params, TRUE);
        return $profile[0];
    }


User profile has change to this:

 function getUserProfile($fbUserId, $fields)
    {
        $profileLibrary = JFBConnectProfileLibrary::getInstance();
        return $profileLibrary->fetchProfile($fbUserId, $fields);
    }

The code below is how I was getting username and first name. How can I achieve this for 5.0

 $fbClient = JFBConnectFacebookLibrary::getInstance();
            $fbUserIdx = $fbClient->getFbUserId();
                
            $fbUserObj = $fbClient->getUserName($fbUserIdx);
            
            $fbUserName = $fbUserObj['name'];
            $fbUserFName = $fbUserObj['first_name'];
            

How can I get the Username and firstname in my component?
The topic has been locked.
Support Specialist
13 years 2 months ago #31916 by alzander
$profileLibrary = JFBConnectProfileLibrary::getInstance();
$fbUser = $profileLibrary->fetchProfile($fbUserId, array(0 => 'first_name', 1 => 'last_name'));
$firstName = $fbUser->get('first_name', 'default-value');
The Profile library now returns a JRegistry value with the profile data. That is much more resilient to problems as you can set a default value, and it won't throw PHP warnings if an incorrect field is accessed.

Hope that helps,
Alex
The topic has been locked.