thebergamo / react-native-fbsdk-next

MIT License
664 stars 165 forks source link

How to do GraphRequest() with v10? #85

Closed diavrank closed 2 years ago

diavrank commented 3 years ago

🐛 Bug Report

Have the following code:

const loginResult = await LoginManager.logInWithPermissions(['public_profile', 'email']);
const { isCancelled } = loginResult;
if (isCancelled) {
    return;
}

const requestManager = new GraphRequestManager();
const request = new GraphRequest(
    '/me',
    {
        httpMethod: 'GET',
        version: 'v10',
        parameters: {
            fields: {
                string: 'id,email,name,short_name,picture'
            }
        }
    },
    (error, profile) => {
        if (error) {
            console.error('There was an error to fetch data from Facebook: ', error);
            return;
        }
        console.log('data from Facebook: ', profile);
        const fbUser = profile as FBUser;
        const loginCredentials: SignupFormValues = {
            avatarUrl: fbUser.picture.data.url,
            email: fbUser.email,
            name: fbUser.name,
            username: fbUser.short_name + fbUser.id.substring(0, 6)
        };
        console.log('loginCredentials: ', loginCredentials);
        //TODO: Do navigation
    }
);
requestManager.addRequest(request).start();

I got this error:

[Wed Aug 04 2021 11:58:34.680]  ERROR    There was an error to fetch data from Facebook:  {"errorCode": -1, "errorMessage": "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1", "exception": "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1", "requestStatusCode": -1, "subErrorCode": -1}

To Reproduce

Ensure to have httpMethod and version fields are in the config parameter as follows:

{
    httpMethod: 'GET',
    version: 'v10',
    parameters: {
        fields: {
            string: 'id,email,name,short_name,picture'
        }
    }
}

Expected Behavior

Get the requested information:

  {"email": "email@example.com", "id": "3232322323", "name": "Foo Bar", "picture": {"data": {"height": 50, "is_silhouette": false, "url": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=asdfasdfasdfasdf", "width": 50}}, "short_name": "Foo"}

It is worth mentioning that if v2.5 is used in version field then it does work, as well as if you skip the version and httpMethod fields, works as well. however, I am not sure which version of Graph API is being used.

Environment

react-native info


System:
    OS: macOS 11.5
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 44.02 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 7.14.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.0 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.2
      System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_261 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.4 => 0.63.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
mikehardy commented 3 years ago

This will not be the answer you want (and maybe someone else has more information?) - but you likely already know more than anyone else in the area, with respect to this module. I've personally never messed with Graph API versions, so I'm not sure how to determine which version is in use, what the incompatibilities are, or how to use one vs the other. I only mention that because it may help with perspective, in that you may be the only person with the motivation + interest in digging in here thus it may be on you to actually dig in + learn + solve the issue unless someone else chimes in

rajeshlousigam commented 2 years ago

Hi, I just got these issues now only. You need to put the version like 'v10.0'

mikehardy commented 2 years ago

If this is something that could use a pointer in the documentation we merge docs PRs quickly (and GitHub makes it really easy to edit an .md file on the web to do a PR all in browser...)