ERROR: Undefined is not an object (evaluating 'NativeGraphRequestManager.start') - react-native-fbsdk (Android)

坚强是说给别人听的谎言 提交于 2019-12-11 04:28:06

问题


Does anyone know how to solve it? Help please! Console error:

Events.js //When i onPress appear the error. I think that my issue is here.

  import React, { Component } from 'react';
  import { Image, StyleSheet, View, TouchableOpacity, Text } from 'react-native';
  const FBSDK = require('react-native-fbsdk');
  const {
    GraphRequest,
    GraphRequestManager,
  } = FBSDK;

  class Eventos extends Component {

    getInfo() {
      const infoRequest = new GraphRequest(
        '/me',
        null,
        this.responseInfoCallback,
      );

      new GraphRequestManager().addRequest(infoRequest).start();
    }

    responseInfoCallback(error, result) {
      if (error) {
        alert('Error fetching data: ' + error.toString());
      } else {
        alert('Success fetching data: ' + result.toString());
      }
    }

    render() {
      return (
        <View>
          <TouchableOpacity
            onPress={() => this.getInfo()}
          >
            <Text>GetInfo</Text>
          </TouchableOpacity>
        </View>

     );
   }
  }

  export default Eventos;

MainActivity.java

  public class MainActivity extends ReactActivity {

      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
      }

      @Override
      protected String getMainComponentName() {
          return "reactnavigationdrawer";
      }
  }

MainApplication.java //I think its okey.

  public class MainApplication extends Application implements ReactApplication {

    private static CallbackManager mCallbackManager = CallbackManager.Factory.create();

    protected static CallbackManager getCallbackManager() {
      return mCallbackManager;
    }

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
      @Override
      public boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
      }

      @Override
       protected List<ReactPackage> getPackages() {
         return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new VectorIconsPackage(),
            new FBSDKPackage(mCallbackManager)
        );
      }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
      return mReactNativeHost;
    }

    @Override
    public void onCreate() {
      super.onCreate();
      AppEventsLogger.activateApp(this);
      SoLoader.init(this, /* native exopackage */ false);
    }
  }

package.json // Am i using deprecated libraries maybe?

        {
            "name": "BealegendApp",
            "version": "0.0.1",
            "private": true,
            "scripts": {
                "start": "node node_modules/react-native/local-cli/cli.js start",
                "test": "jest"
            },
            "dependencies": {
                "firebase": "^4.8.2",
                "lodash": "^4.17.4",
                "react": "16.0.0-alpha.12",
                "react-native": "^0.46.4",
                "react-native-fbsdk": "^0.7.0",
                "react-native-responsive-image": "^2.2.0",
                "react-native-side-menu": "^1.1.3",
                "react-native-textinput-effects": "^0.4.2",
                "react-native-vector-icons": "^4.5.0",
                "react-navigation": "^1.0.0-beta.11",
                "react-redux": "^5.0.6",
                "redux": "^3.7.2",
                "redux-thunk": "^2.2.0"
            },
            "devDependencies": {
                "babel-jest": "20.0.3",
                "babel-preset-react-native": "2.1.0",
                "eslint-config-rallycoding": "^3.2.0",
                "jest": "20.0.4",
                "react-native-vector-icons": "^4.5.0",
                "react-test-renderer": "16.0.0-alpha.12"
            },
            "jest": {
                "preset": "react-native"
            }
        }

This is an app that it has to do a request to facebook graph api. When i onPress appear the error: "Undefined is not an object (evaluating 'NativeGraphRequestManager.start')" I dont know why. Help please!!

if you need more code or details tell me! Thanks!


回答1:


Error: You need an accesToken before to use Graph. In the exaple accessToken isn't defined.

To get it you must login with facebook (LoginButton component). After, you can send this token through props and make request where you want.

It works with the configuration that you can find in the link (in the answer):

Configuration



来源:https://stackoverflow.com/questions/48413336/error-undefined-is-not-an-object-evaluating-nativegraphrequestmanager-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!