Last active
November 3, 2018 19:18
-
-
Save Delf-Lee/7f19d7d78f0237a66f7cac5d6dde9b14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<body> | |
<div id="notice"> | |
이 기능을 이용하기 위해서는 facebook에서 권한을 승인해야 합니다. | |
<a href="https://www.facebook.com/v3.2/dialog/oauth? | |
client_id={app-id} | |
&redirect_uri={redirect-uri} | |
&state={state-param} | |
&scope=email"> <!-- 이메일 권한 추가 --> | |
권한승인 바로가기</a> | |
</div> | |
<div id="welcome" style="display:none"></div> | |
<script> | |
var atr = location.href.match('access_token=([^&]*)'); // 문자열 파싱 | |
console.log('access token regular expression : ', atr); | |
if (atr) { | |
var access_token = atr[1]; // 토큰 추출 | |
console.log('access token : ', access_token); | |
fetch( | |
"https://graph.facebook.com/v3.2" | |
+ "/me" | |
+ "/?access_token=" + access_token | |
+ "&fields=name, email" // 이름과 이메일 요청 | |
) | |
.then(function (raw) { | |
return raw.json(); | |
}) | |
.then(function (result) { | |
if (result.error) { | |
} else { | |
console.log(result); | |
document.querySelector('#notice').style.display = 'none'; | |
document.querySelector('#welcome').style.display = 'block'; | |
document.querySelector('#welcome').innerHTML = "Welcome, " + result.name; | |
} | |
}) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment