Last active
August 28, 2016 15:07
-
-
Save gHashTag/c3c1df48519ab43f8029ac3d0ce68694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View | |
} from 'react-native' | |
const FBSDK = require('react-native-fbsdk') | |
const { | |
LoginButton, | |
AccessToken, | |
GraphRequest, | |
GraphRequestManager | |
} = FBSDK | |
//Create response callback. | |
_responseInfoCallback(error: ?Object, result: ?Object) { | |
if (error) { | |
alert('Error fetching data: ' + error.toString()); | |
} else { | |
alert('Success fetching data: ' + result.toString()); | |
} | |
} | |
// Create a graph request asking for user information with a callback to handle the response. | |
const infoRequest = new GraphRequest( | |
'/me', | |
null, | |
this._responseInfoCallback, | |
); | |
// Start the graph request. | |
new GraphRequestManager().addRequest(infoRequest).start(); | |
class FB extends Component { | |
render () { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.welcome}> | |
Welcome to React Native! | |
</Text> | |
<Text style={styles.instructions}> | |
To get started, edit index.ios.js | |
</Text> | |
<Text style={styles.instructions}> | |
Press Cmd+R to reload,{'\n'} | |
Cmd+D or shake for dev menu | |
</Text> | |
<LoginButton | |
publishPermissions={['publish_actions']} | |
onLoginFinished={ | |
(error, result) => { | |
if (error) { | |
alert('login has error: ' + result.error) | |
} else if (result.isCancelled) { | |
alert('login is cancelled.') | |
} else { | |
AccessToken.getCurrentAccessToken().then( | |
(data) => { | |
alert(data.accessToken.toString()) | |
} | |
) | |
} | |
} | |
} | |
onLogoutFinished={() => alert('logout.')}/> | |
</View> | |
) | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#F5FCFF' | |
}, | |
welcome: { | |
fontSize: 20, | |
textAlign: 'center', | |
margin: 10 | |
}, | |
instructions: { | |
textAlign: 'center', | |
color: '#333333', | |
marginBottom: 5 | |
} | |
}) | |
AppRegistry.registerComponent('FB', () => FB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment