from django.shortcuts import render, redirect
from django.views import View
from django.http import JsonResponse
KAKAO_REST_API_KEY = "e98f80e934f91eeaf7ed339595cdffb5"
class KakaoSignInView(View):
def get(self, request):
app_key = KAKAO_REST_API_KEY
redirect_uri = 'http://127.0.0.1:8000/users/signin/kakao/callback'
kakao_auth_api = 'https://kauth.kakao.com/oauth/authorize?response_type=code'
return redirect(
f'{kakao_auth_api}&client_id={app_key}&redirect_uri={redirect_uri}'
)
import requests
class KaKaoSignInCallBackView(View):
def get(self, request):
auth_code = request.GET.get('code')
kakao_token_api = 'https://kauth.kakao.com/oauth/token'
data = {
'grant_type': 'authorization_code',
'client_id': KAKAO_REST_API_KEY,
'redirection_uri': 'http://localhost:8000/oauth',
'code': auth_code
}
token_response = requests.post(kakao_token_api, data=data)
access_token = token_response.json().get('access_token')
user_info_response = requests.get('https://kapi.kakao.com/v2/user/me', headers={"Authorization": f'Bearer ${access_token}'})
return JsonResponse({"user_info": user_info_response.json()})
다른 사람 API로 했을때는 값을 받아 올 수 있는데 저 계정의 REST API 키를 사용하면 401로 acess token을 받아올 수 없는데, 어떤 문제가 있는지 궁금합니다…!!