Skip to content

add picture field for user's avatar#267

Merged
overtrue merged 1 commit intoovertrue:4.xfrom
woei66:4.x
Sep 1, 2023
Merged

add picture field for user's avatar#267
overtrue merged 1 commit intoovertrue:4.xfrom
woei66:4.x

Conversation

@woei66
Copy link
Contributor

@woei66 woei66 commented Sep 1, 2023

To get the user's avatar correctly, we need to add "picture" field in the $fields array.

Ps.
According to the previous code, I used below code to get the avatar of users correctly.
But I found that the code is changed after I did the testing and I didn't test the new code, I shared the code I used which can fetch users's avatar correctly.

protected function mapUserToObject(array $user): User
    {
        $userId = $user['id'] ?? null;
        if(isset($user['picture'])) {
            if(empty($user['picture']['data']['is_silhouette'])) {
                $avatarUrl = $user['picture']['data']['url'];
            } else {
                $avatarUrl = $this->graphUrl . '/' . $this->version . '/' . $userId . '/picture?type=normal';
            }
        } else {
            $avatarUrl = null;
        }

        $firstName = $user['first_name'] ?? null;
        $lastName = $user['last_name'] ?? null;

        return new User(
            [
                'id' => $user['id'] ?? null,
                'nickname' => null,
                'name' => $firstName . ' ' . $lastName,
                'email' => $user['email'] ?? null,
                'avatar' => $avatarUrl,
                'avatar_original' => $userId ? $avatarUrl . '?width=1920' : null,
            ]
        );
    }

I tried to dump the $user array and it's content is similar below:

Array
(
    [first_name] => xxx
    [last_name] => xxx
    [picture] => Array
        (
            [data] => Array
                (
                    [height] => 50
                    [is_silhouette] =>
                    [url] => https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=xxx&height=50&width=50&ext=xxx&hash=xxx
                    [width] => 50
                )
        )
    [id] => xxx
)

@overtrue overtrue merged commit dcbb1ee into overtrue:4.x Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants