Commit 0676afa0 by agan

修改facebook登陆

parent 86099e9a
Showing with 35 additions and 31 deletions
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title></title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<script src="login.js"></script> <script src="login.js"></script>
</head> </head>
<body> <body>
<script> <script>
function statusChangeCallback(response) { // Called with the results from FB.getLoginStatus(). function statusChangeCallback(response) { // Called with the results from FB.getLoginStatus().
console.log(response); console.log(response);
if (response.status === 'connected') { // Logged into your webpage and Facebook. if (response.status === 'connected') { // Logged into your webpage and Facebook.
testAPI(response.authResponse.accessToken); testAPI(response.authResponse.accessToken);
} else { // Not logged into your webpage or we are unable to tell. } else { // Not logged into your webpage or we are unable to tell.
if(url_get_params().error == undefined || url_get_params().code == undefined){ if (url_get_params().error == undefined || url_get_params().code == undefined) {
window.location.href = "https://www.facebook.com/v6.0/dialog/oauth?client_id=382456482257502&redirect_uri=https://www.footseen.com/footseen/login/index.html&state=045478b9202f7c4913ab5366eaf15f8a" window.location.href = "https://www.facebook.com/v6.0/dialog/oauth?client_id=382456482257502&redirect_uri=https://www.footseen.com/footseen/login/index.html&state=045478b9202f7c4913ab5366eaf15f8a"
} else { } else {
var obj = { var obj = {
"cid":22, "cid": 22,
"reqCode": new Date().getTime(), "reqCode": new Date().getTime(),
"data": { "data": {
"msg":'facebook登录', "msg": 'facebook登录',
"type":2, "type": 2,
"id":"", "id": "",
"name":"", "name": "",
"url":"", "url": "",
"token":"" "token": ""
} }
} }
var obj2 = JSON.stringify(obj); var obj2 = JSON.stringify(obj);
...@@ -38,28 +40,28 @@ ...@@ -38,28 +40,28 @@
function checkLoginState() { // Called when a person is finished with the Login Button. function checkLoginState() { // Called when a person is finished with the Login Button.
FB.getLoginStatus(function(response) { // See the onlogin handler FB.getLoginStatus(function (response) { // See the onlogin handler
statusChangeCallback(response); statusChangeCallback(response);
}); });
} }
window.fbAsyncInit = function() { window.fbAsyncInit = function () {
FB.init({ FB.init({
appId : '382456482257502', appId: '382456482257502',
xfbml : true, xfbml: true,
cookie : true, // enable cookies to allow the server to access cookie: true, // enable cookies to allow the server to access
version : 'v6.0' version: 'v12.0'
}); });
FB.getLoginStatus(function(response) { // Called after the JS SDK has been initialized. FB.getLoginStatus(function (response) { // Called after the JS SDK has been initialized.
statusChangeCallback(response); // Returns the login status. statusChangeCallback(response); // Returns the login status.
}); });
}; };
(function(d, s, id) { // Load the SDK asynchronously (function (d, s, id) { // Load the SDK asynchronously
var js, fjs = d.getElementsByTagName(s)[0]; var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id; js = d.createElement(s); js.id = id;
...@@ -69,18 +71,18 @@ ...@@ -69,18 +71,18 @@
function testAPI(token) { function testAPI(token) {
FB.api('/me?fields=email,name,id,picture.width(200).height(200)', function(response) { FB.api('/me?fields=email,name,id,picture.width(200).height(200)', function (response) {
console.log('登录成功'); console.log('登录成功');
var obj = { var obj = {
"cid":22, "cid": 22,
"reqCode": new Date().getTime(), "reqCode": new Date().getTime(),
"data": { "data": {
"msg":'facebook登录', "msg": 'facebook登录',
"type":1, "type": 1,
"id":response.id, "id": response.id,
"name":response.name, "name": response.name,
"url":response.picture.data.url, "url": response.picture.data.url,
"token":token "token": token
} }
} }
var obj2 = JSON.stringify(obj); var obj2 = JSON.stringify(obj);
...@@ -92,16 +94,17 @@ ...@@ -92,16 +94,17 @@
function url_get_params() { function url_get_params() {
var url = location.href; var url = location.href;
var theRequest = new Object(); var theRequest = new Object();
if(url.indexOf("?") != -1) { if (url.indexOf("?") != -1) {
var str = url.substr(url.indexOf("?") + 1); var str = url.substr(url.indexOf("?") + 1);
strs = str.split("&"); strs = str.split("&");
for(var i = 0; i < strs.length; i++) { for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
} }
} }
return theRequest; return theRequest;
} }
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment