-
-
Save ttpro1995/a07195682451b6dada6fa189f3ca5e68 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
*/ | |
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
TouchableHighlight, | |
Text, | |
View | |
} from 'react-native'; | |
const FBSDK = require('react-native-fbsdk'); | |
const { | |
LoginButton, | |
ShareDialog, | |
AccessToken, | |
GraphRequest, | |
GraphRequestManager, | |
} = FBSDK; | |
var meow_accesstoken; | |
// Create a graph request asking for user information with a callback to handle the response. | |
class testFacebookAgain extends Component { | |
//Create response callback. | |
_responseInfoCallback(error: ?Object, result: ?Object) { | |
alert("meow response"); | |
if (error) { | |
alert('Error fetching data: ' + error.toString()); | |
} else { | |
alert('Success fetching data: ' + result.toString()); | |
} | |
} | |
testRequestGraphAPI(){ | |
const infoRequest = new GraphRequest( | |
'/me?fields=id,name', | |
null, | |
this._responseInfoCallback, | |
); | |
new GraphRequestManager().addRequest(infoRequest).start(); | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.welcome}> | |
Welcome to React Native! | |
</Text> | |
<Text style={styles.instructions}> | |
To get started, edit index.android.js | |
</Text> | |
<Text style={styles.instructions}> | |
Below is a logging button | |
</Text> | |
<LoginButton | |
publishPermissions={["publish_actions,user_birthday, user_religion_politics, user_relationships, user_relationship_details, user_hometown, user_location, user_likes, user_education_history, user_work_history, user_website, user_managed_groups, user_events, user_photos, user_videos, user_friends, user_about_me, user_status, user_games_activity, user_tagged_places, user_posts, user_actions.video, user_actions.news, user_actions.books, user_actions.music, user_actions.fitness, public_profile, basic_info"]} | |
onLoginFinished={ | |
(error, result) => { | |
if (error) { | |
alert("login has error: " + result.error); | |
} else if (result.isCancelled) { | |
alert("login is cancelled."); | |
} else { | |
AccessToken.getCurrentAccessToken().then( | |
(data) => { | |
meow_accesstoken = data.accessToken | |
alert(meow_accesstoken.toString()) | |
} | |
) | |
} | |
} | |
} | |
onLogoutFinished={() => alert("logout.")}/> | |
<TouchableHighlight style={styles.share} | |
onPress={this.testRequestGraphAPI.bind(this)}> | |
<Text style={styles.shareText}>Test request graph API</Text> | |
</TouchableHighlight> | |
</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, | |
}, | |
shareText: { | |
fontSize: 20, | |
margin: 10, | |
} | |
}); | |
AppRegistry.registerComponent('testFacebookAgain', () => testFacebookAgain); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment