0

I'm trying to get a list of posts from a Facebook page, but when I send my request via GraphRequestManager, it throws an error "undefined is not an object (evaluating 'NativeGraphRequestManager.start'). I've correctly linked FBSDK with my project and I'm using Android to test, and I followed the React Native guide for FBSDK but it still throws an error. Any ideas? Using RN 0.47 and FBSDK 0.6.1.

Here is a snippet of my code:

const FBSDK = require('react-native-fbsdk');
const {
  GraphRequest,
  GraphRequestManager,
} = FBSDK;

export default class FeedView extends Component {
 constructor(props) {
   super(props);
   this.state = {
     posts: null,
   } 
 }

 componentDidMount() {
   this.setState({
     refreshing: false,
     posts: this._getPosts(),
   });
 }

 _getPosts() {
   const getRequestConfig = {
     httpMethod: 'GET',
     version: 'v2.10',
     parameters: null,
     accessToken: accessToken,
   }

   const infoRequest = new GraphRequest(
     page,
     getRequestConfig,
     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());
    console.log(result.toString());
  }
}
  • debug your code and see what each part contains. for example, is "page" defined? where is the api call? – andyrandy Sep 01 '17 at 10:56
  • Yes, page and accesstoken are defined. "page" contains the Graph API call e.g "/PAGE_ID/posts". Also I tried logging the GraphRequestManager object to see its prototypes and they indeed do contain start() and addRequest(). – Jerico Alcaras Sep 01 '17 at 11:40

1 Answers1

0

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.

Diego Barranco
  • 89
  • 1
  • 2
  • 9