YujeLee

카카오 API기반 로그인, 나에게 전송하기

1 +var http = require('http');
2 +var fs = require('fs');
3 +var app = http.createServer(function(request,response){
4 + var url=request.url;
5 + if(url == '/'){
6 + url = '/send.html';
7 + }
8 + if(url == '/loginmainpage'){
9 + url='/loginmainpage.html';
10 + }
11 + response.writeHead(200);
12 + response.end(fs.readFileSync(__dirname+url));
13 +});
14 +
15 +app.listen(8080);
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <meta charset="utf-8"/>
5 + <title>login page title</title>
6 + <script src="https://developers.kakao.com/sdk/js/kakao.js"></script>
7 +
8 + </head>
9 +<body>
10 + <a id="kakao-login-btn"></a>
11 + <a href="http://developers.kakao.com/logout"></a>
12 + <script>
13 + Kakao.init('0678e32dab56db1c52ac63ab4ccb7663');
14 +
15 + console.log(Kakao.isInitialized());
16 +
17 + Kakao.Auth.createLoginButton({
18 + container: '#kakao-login-btn',
19 + success: function(authObj){
20 + console.log(JSON.stringify(authObj));
21 + alert(JSON.stringify(authObj));//authObj -> 토큰임.
22 + redirectUrl
23 + },
24 + fail: function(err){
25 + alert(JSON.stringify(err));
26 + }
27 + })
28 + console.log('hi');
29 + Kakao.Link.createDefaultButton({
30 + container: ".kakao-link",
31 + objectType: "feed",
32 + content:{
33 + title: "안녕하세요",
34 + description: "반갑습니다.",
35 + link:{
36 + webUrl: "https://www.naver.com/",
37 + mobileWebUrl: "https://www.naver.com/"
38 + },
39 + },
40 + })
41 + function kakaoLogout(){
42 + Kakao.Auth.logout(function(response){
43 + alert(response+'logout');
44 + Kakao.API.request({
45 + url: '/v1/user/unlink',
46 + success: function(response) {
47 + console.log(response);
48 + },
49 + fail: function(error) {
50 + console.log(error);
51 + console.log("error");
52 + },
53 + })
54 + })
55 + }
56 +</script>
57 +<script>
58 + console.log('hi');
59 + Kakao.Link.createDefaultButton({
60 + container: ".kakao-link",
61 + objectType: "feed",
62 + content:{
63 + title: "안녕하세요",
64 + description: "반갑습니다.",
65 + link:{
66 + webUrl: "https://www.naver.com/",
67 + mobileWebUrl: "https://www.naver.com/"
68 + },
69 + },
70 + })
71 +</script>
72 +
73 +<a onclick="kakaoLogout();">카카오 로그아웃</a>
74 +</body>
75 +</html>
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title>login main page title</title>
5 + </head>
6 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <meta charset="utf-8"/>
5 + <title>send page title</title>
6 + <script src="https://developers.kakao.com/sdk/js/kakao.js"></script>
7 + <script src="send.js"></script>
8 + </head>
9 + <body>
10 + <a onclick="sendLink()">보내기</a>
11 + </body>
12 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +function sendLink(){
2 + Kakao.init('0678e32dab56db1c52ac63ab4ccb7663')
3 + Kakao.Link.sendDefault({
4 + objectType: 'feed',
5 + content:{
6 + title: "관심있는 공연 정보",
7 + description: '주소-> http://naver.com',
8 + imageUrl:'http://k.kakaocdn.net/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png',
9 + link:{
10 + mobileWebUrl: 'http://naver.com',
11 + webUrl: 'http://naver.com',
12 + },
13 + },
14 + buttons: [
15 + {
16 + title: '웹으로 보기',
17 + link: {
18 + mobileWebUrl: 'http://naver.com',
19 + webUrl: 'http://naver.com',
20 + },
21 + },
22 + {
23 + title: '웹으로 보기',
24 + link: {
25 + mobileWebUrl: 'http://naver.com',
26 + webUrl: 'http://naver.com',
27 + },
28 + },
29 + ],
30 + })
31 +};
...\ No newline at end of file ...\ No newline at end of file