-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
203 lines (179 loc) · 5.7 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import React, { Component } from 'react';
import {
Image,
Platform,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
Dimensions,
View,
FlatList,
Avatar,
} from 'react-native';
import FBSDK, { LoginManager } from 'react-native-fbsdk';
//https://github.com/facebook/react-native-fbsdk
const {
LoginButton,
AccessToken,
GraphRequest,
GraphRequestManager
} = FBSDK;
export class Login extends Component {
constructor(props) {
super(props);
console.log("Props are: " + this.props);
}
// Create response callback.
_userFriendsResponseInfoCallback = (error: ?Object, result: ?Object) => {
if (error) {
alert('Error fetching data: ' + error.toString());
console.log(Object.keys(error));// print all enumerable
console.log(error.errorMessage); // print error message
} else {
console.log(Object.keys(result));
meow_json = JSON.stringify(result); // result => JSON
console.log(meow_json); // print JSON
user_friends = []
let myId = JSON.stringify(result.id);
let myPicture = JSON.stringify(result.picture.data.url);
let fbookFriendData = result.friends.data;
for (var i = 0; i < fbookFriendData.length; i++) {
let friendId = fbookFriendData[i].id;
let friendName = fbookFriendData[i].name;
let friendPic = 'https://graph.facebook.com/' + friendId + '/picture?type=small';
user_friends = [...user_friends, new User(friendId, friendName, friendPic)];
// console.log('friendId is: ' + friendId);
// console.log('friendName is: ' + friendName);
// console.log('friendPic is: ' + friendPic);
}
user_friends.sort(function(a, b) {
return (a.state.name < b.state.name) ? -1 : (a.state.name > b.state.name) ? 1 : 0;
});
for (var i = 0; i < user_friends.length; i++) {
console.log(user_friends[i].state.name);
}
if (typeof(this.props) == 'undefined') {
console.log("Slaughter Gang: this.props is undefined");
}
this.props.callbackFromParent(user_friends);
}
}
_testUserFriends(accessToken) {
const infoRequest = new GraphRequest(
'/me',
{
parameters: {
fields: {
string: 'name,friends,picture' // what you want to get
},
access_token: {
string: accessToken.toString() // put your accessToken here
}
}
},
this._userFriendsResponseInfoCallback // make sure you define _responseInfoCallback in same class
);
new GraphRequestManager().addRequest(infoRequest).start();
}
render() {
return (
<View>
<LoginButton
// publishPermissions={["publish_actions"]}
readPermissions={["public_profile", "email", "user_friends"]}
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());
//Go to Login Complete Screen
//Determine if this was their first login onto the app
//
this._testUserFriends(data.accessToken);
}
)
}
}
}
onLogoutFinished={() => alert("logout.")} />
</View>
);
}
}
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {data: []};
}
myCallback = (dataFromChild) => {
this.setState({ data: dataFromChild });
for (var i = 0; i < this.state.data.length; i++) {
console.log("name is: " + this.state.data[i].state.name);
}
}
render() {
return (
<View style={styles.container}>
<View style={styles.whiteBox}>
<Image style={styles.dingoCircle}
source={require('./img/dingo_circle.png')} />
<Text style={styles.description}>Logging in with</Text>
<Text style={styles.description}>Facebook lets</Text>
<Text style={styles.description}>you easily add</Text>
<Text style={styles.description}>friends to notify.</Text>
<View style={styles.loginButton}>
<Login callbackFromParent={this.myCallback.bind(this)} />
</View>
<View style={styles.userList}>
<FlatList
data={this.state.data}
/>
</View>
</View>
</View>
);
}
}
const window = Dimensions.get('window');
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#191979',
},
statusBarUnderlay: {
height: 24,
backgroundColor: 'rgba(0,0,0,0.2)',
},
userList: {
margin: 40,
},
whiteBox: {
flex: 1,
margin: 20,
backgroundColor: '#fff',
alignItems: 'center',
borderRadius: 30,
},
dingoCircle: {
marginTop: window.height/6,
marginBottom: window.height/15,
width: window.width/3,
height: window.width/3,
},
description: {
fontFamily: 'Avenir',
fontSize: window.width / 15,
alignItems: 'center',
color: '#353535',
},
loginButton: {
marginTop: window.height / 15
}
});
module.exports = Login;