//引入Twitter
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"));
// 初始化Twitter登錄並定義login_twitter登錄方法。
var log = console.log;
hello.init(
{ 'twitter': '***************' }, //App_key
{ 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.dir(p);
//已獲取用戶信息,在此處理
var response = { 'id': p.id, 'first_name': p.name, 'last_name': p.last_name, 'picture': p.thumbnail, 'link': 'https://twitter.com/' + p.screen_name, 'login_type': 'twitter' };
console.dir(response);
}, log);
}