본문 바로가기
개발/python, python frameworks

카카오 로그인 (python에 붙이기)

by 개발자종혁 2020. 3. 23.
728x90

 

import requests
import json


host = 'kapi.kakao.com'
admin_key = 'admin key'
user_id = '유저 아이디'


def getAllUsers():
    headers = {
                'Host': host,
                'Authorization': f'KakaoAK {admin_key}',
                'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
            }

    res = requests.get(f'https://{host}/v1/user/ids', headers=headers)
    print(res.json())


def getUserInfo():
    headers2 = {
                'Host': host,
                'Authorization': f'KakaoAK {admin_key}',
                # 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
            }
    data = {
        'target_id_type': 'user_id',
        'target_id': "",
    }
    res = requests.post(f'https://{host}/v2/user/me', headers=headers2, data=data)
    result = res.json()
    print(result)
    print(res.status_code)


# def unlinkUser():
#     headers2 = {
#                 'Host': host,
#                 'Authorization': f'KakaoAK {admin_key}',
#                 # 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
#             }
#     data = {
#         'target_id_type': 'user_id',
#         'target_id': "1307612408",
#     }
#     res = requests.post(f'https://{host}/v1/user/unlink', headers=headers2, data=data)
#     result = res.json()
#     print(result)
#     # print(result['msg'])
#     # print(result['properties']['is_email_verified'])
#     # print(result['properties']['email'])
#     print(res.status_code)

# params = {
#     "client_id": "클라이언트 아이디"
# }
# res = requests.get(f'https://{host}/v2/user/me', params=params)
# print(res.text)


# getAllUsers()
getUserInfo()
# unlinkUser()
728x90

'개발 > python, python frameworks' 카테고리의 다른 글

PyInstaller shell 없애기  (0) 2020.04.21
python(flask)에서 DTO 활용하기(예제)  (0) 2020.04.03
AES256/ base64 암호화 with python  (0) 2020.03.30
python flask - blueprint  (0) 2020.03.12

댓글