-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainView.js
86 lines (68 loc) · 1.86 KB
/
MainView.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
var Observable = require("FuseJS/Observable");
var Auth = require("Auth");
function stringContainsString(s1, s2){
return s1.indexOf(s2) > -1;
}
var showWebView = Observable(false);
var accessToken = Observable("");
var client_id = Auth.client_id;
var url = Observable("about:blank");
function login(){
url.value = "https://www.facebook.com/dialog/oauth?client_id=" + client_id + "&response_type=token&redirect_uri=https://www.facebook.com/connect/login_success.html";
showWebView.value = true;
}
function pageLoaded(res){
var uri = JSON.parse(res.json).url;
console.log("Final URI: " + uri);
if (stringContainsString(uri, "access_token=")){
var tmp = uri.split("access_token=")[1];
var at = tmp.split("&")[0];
accessToken.value = at;
showWebView.value = false;
getMe();
}
}
var myName = Observable("");
var myPicture = Observable();
var hasProfile = Observable(false);
function Funone(){
var url = "https://graph.facebook.com/v2.5/me?fields=name&access_token=" + accessToken.value;
fetch(url,{
method:"GET"
}).then(function(result){
return result.json();
}).then(function(resultJson){
myName.value = resultJson.name;
return getone;
}).catch(function(error){
console.log("Error: " + error);
});
}
function Funtwo(){
console.log("Trying to get picture");
var pictureUrl = "https://graph.facebook.com/v2.5/me/picture?type=large&redirect=false&access_token=" + accessToken.value;
fetch(pictureUrl, {
method:"GET"
}).then(function(result){
return result.json();
}).then(function(resultJson){
myPicture.value = resultJson.data.url;
hasProfile.value = true;
}).catch(function(error){
console.log("Error: " + error);
});
}
function getMe(){
Funone();
Funtwo();
}
module.exports = {
login:login,
pageLoaded: pageLoaded,
url: url,
getMe : getMe,
myName: myName,
myPicture: myPicture,
showWebView: showWebView,
hasProfile: hasProfile
};