Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getUserProfile() default fields #166

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

drezo
Copy link

@drezo drezo commented Jan 17, 2019

Hello! ✌️

Permissions my application ("locale", "timezone", "gender" unavailable):

2019-01-17 11 21 21

Next, we downloaded current version package (1.0.16), used method "getUserProfile()" and get the follow error 😑:

{  
   "error":{  
      "message":"(#100) Insufficient permission to access user profile.",
      "type":"OAuthException",
      "code":100,
      "error_subcode":2018247,
      "fbtrace_id":"CZW1EcCa704"
   }
}

Changed method "getUserProfile()":

getUserProfile(userId, fields) {
    const defaultFields = ['id', 'name', 'first_name', 'last_name', 'profile_pic'];
    if (!Array.isArray(fields)) {
      throw new Error('Fields is supposed to be an array');
    } else Array.prototype.push.apply(defaultFields, fields.map(field => field.trim()));
    const mergeFields = defaultFields.join(',');
    const url = `https://graph.facebook.com/${this.graphApiVersion}/${userId}?fields=${mergeFields}&access_token=${this.accessToken}`;
    return fetch(url)
      .then(res => res.json())
      .catch(err => console.log(`Error getting user profile: ${err}`));
  }

Thanks!

@drezo
Copy link
Author

drezo commented Aug 4, 2019

@Charca

What do you say? 🙄

Copy link
Owner

@Charca Charca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @drezo, thanks for the PR and sorry for the big delay. I haven't been paying much attention to this project or the chatbot scene for the last year, I apologize if this makes your job harder.

The PR looks good for the most part, I left a couple of comments for thing that I'd like to see changed. Please let me know what you think.

* @returns {Promise}
*/
getUserProfile(userId) {
const url = `https://graph.facebook.com/${this.graphApiVersion}/${userId}?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=${this.accessToken}`;
getUserProfile(userId, fields) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give fields a default value of []? Otherwise, the check on line 344 would make the method fail for people who are calling it directly without fields.


| Param | Type | Default | Required |
|:------|:-----|:--------|:---------|
| `fields` | array | ['id', 'name', 'first_name', 'last_name', 'profile_pic'] | `N` |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we should change this description. The default value of the fields param is not ['id', 'name', ... ], it's an empty array. When you specify fields, you're not overwriting this default value, you're extending it. I think we should either change the behavior to allow specifying/overwriting all fields, or change this description and maybe the param name to extraFields so that it's clear that you're extending the default. What do you think?

@lehainam-dev
Copy link
Contributor

Hi,
I think this PR is important and resolve a lot issues #150 with recent policy changes of Facebook.
I wonder if @drezo could update the PR?
Thanks.

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.

3 participants