# Retrieve Facebook User Name from Profile

**URL:** <https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056>\
**Category:** Get Help\
**Tags:** user-profile, facebook, auth0\
**Created:** [October 9, 2021, 4:06pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056 "2021-10-09T16:06:34Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![CueToDo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cuetodo/32/21184_2.png) [@CueToDo](https://community.auth0.com/u/CueToDo)\
**Post date:** [October 9, 2021, 4:06pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/1 "2021-10-09T16:06:34Z")

</div>

I’ve spent the afternoon trying to retrieve basic user profile information from Facebook without success.

Going back to basics I’ve set up the sample project from [Auth0 Angular SDK Quickstarts: Login](https://auth0.com/docs/quickstart/spa/angular/01-login#show-user-profile-information)

Logging in and displaying name(email) and nickname works fine, but I cannot display given\_name or family\_name. (I’ve also tried user\_location and user\_hometown)

In Auth0 dashboard under **Social Connections** , public\_profile is ticked and cannot be unticked, but when I **Try Connection** profile/full name is not retrieved (nor location)

So it would seem to be a configuration issue within the Auth0 dashboard, rather than an application issue.

What should I try next?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 11, 2021, 5:02pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/3 "2021-10-11T17:02:56Z")

</div>

Hi @CueToDo,

Welcome to the Auth0 Community!

I understand you are trying to retrieve the `given_name` and `family_name` properties from a Facebook connection user.

Here is what is returned if I use the default Facebook connection settings:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/f/3/f3eb554515370b1f032efd705df738784daa3385.png)

Can you share an example of what is returned in your request?

---

<div class="post-metadata">

**Author:** ![CueToDo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cuetodo/32/21184_2.png) [@CueToDo](https://community.auth0.com/u/CueToDo)\
**Post date:** [October 11, 2021, 7:01pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/4 "2021-10-11T19:01:46Z")

</div>

Thanks Dan,

For some reason, when I “Try Connection” for Facebook, I’m getting back an auth0 response.

Hopefully a simple fix here somewhere … !

 ![image](https://global.discourse-cdn.com/auth0/original/3X/c/d/cdfc66ca9561114e1782625784fb246f91012c95.png)

![image](https://global.discourse-cdn.com/auth0/original/3X/2/3/230d776701006159a8e4b8870582f840f05c40de.png)

![image](https://global.discourse-cdn.com/auth0/original/3X/3/8/38e2cd63c0117741162460ebf77e355d8d23cb15.png)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 12, 2021, 5:06pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/5 "2021-10-12T17:06:16Z")

</div>

Would you please DM me your tenant name?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 12, 2021, 10:34pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/6 "2021-10-12T22:34:05Z")

</div>

It looks like this is related to account linking. Checkout this doc that tells how to add the missing info:

> **[Link User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/link-user-accounts)**
>
> Understand how to link user accounts from various identity providers, so your users can authenticate from any account and be recognized by your app.

---

<div class="post-metadata">

**Author:** ![CueToDo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cuetodo/32/21184_2.png) [@CueToDo](https://community.auth0.com/u/CueToDo)\
**Post date:** [October 13, 2021, 3:44pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/7 "2021-10-13T15:44:53Z")

</div>

Excellent, thanks Dan, adding the rule retrieves the extra data from the secondary identity.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 13, 2021, 5:17pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/8 "2021-10-13T17:17:30Z")

</div>

Glad we found a solution. Let me know if there is anything else!

---

<div class="post-metadata">

**Author:** ![CueToDo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cuetodo/32/21184_2.png) [@CueToDo](https://community.auth0.com/u/CueToDo)\
**Post date:** [October 13, 2021, 8:50pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/9 "2021-10-13T20:50:29Z")

</div>

Thanks Dan, there is actually - just a quick follow up about verifying what gets saved to the primary identity. Is it possible to do that from the dashboard?

As I said, I can save given\_name and family\_name and retrieve those values in my application …

but I’d really like to be able to access location. I’ve ticked this under the facebook connection and can view this under the Raw Json for myself as a user.

![image](https://global.discourse-cdn.com/auth0/original/3X/3/0/304337cd0dd96323731b6fb02fb920b7e66b0603.png)

However, I’ve tried a variety of ways to add this to the primary identity so that I can see this in my application just like given\_name.

Here’s my latest attempt: I’ve put identities in the outer loop and have changed the dot notation to array accessor with a string literal (despite warnings when editing the rule, the dot notation does not work). When I Iog in, I can see the value in the debug logs

![image](https://global.discourse-cdn.com/auth0/original/3X/a/2/a29accbcc58857be1846b6967d70ed23f00177d7.png)

How can I verify that this is saved? I can’t see given\_name in the dashboard although it must be as this is returned to my application.

Here’s my rule:

```auto
function(user, context, callback) {
  
  const propertiesToComplete = ["given_name", "family_name"];

  // go over each property and try to get missing
  // information from secondary identities
  for(var identity of user.identities) {
    console.log(identity.provider);
    if (identity.provider === "facebook" && identity.profileData && identity.profileData.hometown){
      console.log("Hometown!", identity.profileData["hometown"]["name"]);
      user["hometown"] = identity.profileData["hometown"]["name"]; 
    }
    for(var property of propertiesToComplete) {
      // if (!user[property]) {
        if (identity.profileData && identity.profileData[property]) {
          user[property] = identity.profileData[property];
          break;
        }
      // }
    }
  }
  
  callback(null, user, context);
}

```

I seem to be so close, but missing a vital step.

Many thanks again for your help!

Alex

---

<div class="post-metadata">

**Author:** ![CueToDo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cuetodo/32/21184_2.png) [@CueToDo](https://community.auth0.com/u/CueToDo)\
**Post date:** [October 13, 2021, 8:52pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/10 "2021-10-13T20:52:15Z")

</div>

PS location AND hometown are in the Raw Json with identical values!

![image](https://global.discourse-cdn.com/auth0/original/3X/5/3/53dec7d28012d3fc35ca887cf75bf9a164970853.png)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 14, 2021, 5:49pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/11 "2021-10-14T17:49:31Z")

</div>

> [@CueToDo](#):
>
> How can I verify that this is saved? I can’t see given\_name in the dashboard although it must be as this is returned to my application.

If you are trying to get `location` in the id token you can add it directly as a custom claim. This claim is specific to facebook identities.

---

<div class="post-metadata">

**Author:** ![CueToDo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cuetodo/32/21184_2.png) [@CueToDo](https://community.auth0.com/u/CueToDo)\
**Post date:** [October 14, 2021, 8:33pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/12 "2021-10-14T20:33:56Z")

</div>

Excellent, thanks again Dan, I appreciate your time - all sorted now!

It looks like there is a limitation on what can be attached to the user object, including location.

This simple test shows expected result in console, but property test is not sent to client application.

var propertyName=“test”;  
user[propertyName] = “bajingo”;  
console.log(“user[propertyName]”, propertyName, user[propertyName]);

As I already had a rule for a custom claim, I’ve now added location to that rule - and that can be retrieved from token when sent to my API.

Happy days!

Thanks again!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 14, 2021, 8:47pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/13 "2021-10-14T20:47:04Z")

</div>

Thanks for sharing your solution! Let us know if you run into anything else. 😄

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 29, 2021, 8:47pm UTC](https://community.auth0.com/t/retrieve-facebook-user-name-from-profile/71056/14 "2021-10-29T20:47:34Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
