Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native app and Facebook SDK

I successfully managed to create a native component that successfully logins a user into Facebook. So, in my react-native app, I've got the access token and the userId. Now, I'd like to use Facebook SDK (for example, the Graph API) to access to some basic infos (profile name, profile picture, etc.) and to do basic things (share a post, etc.)

At this point I'm quite lost: how can I do that? Can I use the fetch API? Do I need to add some node plugin to my app (I was looking for this: https://github.com/Thuzi/facebook-node-sdk)?

like image 774
Muntaner Avatar asked Feb 11 '23 03:02

Muntaner


2 Answers

You can make a request like this using the fetch API where query can be something like https://graph.facebook.com/me?access_token=token_you_got

fetch('https://graph.facebook.com/me?access_token=token_you_got')
  .then(response => response.json())
  .then(json => this._handleResponse(json.response))
  .catch(error => 
     this.setState({
      isLoading: false,
      message: 'Something bad happened ' + error
   }));

More information here: http://www.raywenderlich.com/99473/introducing-react-native-building-apps-javascript

like image 195
Shireesh Asthana Avatar answered Feb 13 '23 06:02

Shireesh Asthana


I know its a little late to the party but for future reference to anyone who is going to integrate with Facebook with React-Native should consider using this wrapper around the ios Facebook SDK.

https://github.com/facebook/react-native-fbsdk

like image 38
Russell Maxfield Avatar answered Feb 13 '23 07:02

Russell Maxfield