-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
53 lines (48 loc) · 1.52 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script src="http://adodson.com/hello.js/dist/hello.all.js"></script>
<body>
<button class="twBtn" onclick = "login_twitter('twitter')" >login</button>
</body>
<script>
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
var log = console.log;
hello.init({
'twitter' : 'l6cu0ZoxWSUPEB9JtxulCVLae'
},
{
// redirect_uri:'/', //代理后的重定向路径,可不填
oauth_proxy: 'https://auth-server.herokuapp.com/proxy' //这里使用默认的代理
});
function login_twitter(network){ //登录方法,并将twitter 作为参数传入
// Twitter instance
var twitter = hello(network);
// Login
twitter.login().then( function(r){
// Get Profile
return twitter.api('/me');
}, log ) .then( function(p){
console.log("Connected to "+ network+" as " + p.name);
var res = JSON.stringify(p);//因为得不到token,但是这步已经得到用户所有信息,所以将用户信息转成JSON字符串给后台
self.location= '/home/login.twLogin.do?result='+res;
}, log );
}
</script>
</html>