까시남의 소소한 일상들..
네이버 커머스API 사전작업 그리고 토큰 본문
>>사전작업
-- 네이버 스마트 스토어개설 필수
-- 스토어 -> 판매자정보 -> 매니저관리 -> 통합매니저 권환 획득(스토어에서 1:1문의 폼 활용)
스마트스토어 고객센터
스마트스토어 고객센터 도움말을 확인해 보세요.
help.sell.smartstore.naver.com
--통합매니저 아이디로 로그인 후 API 어플리케이션 등록
네이버 커머스API센터
커머스API를 활용해서 다양한 아이디어로 새로운 기회를 잡아보세요.
apicenter.commerce.naver.com
>>> 문서
[중요] API 업그레이드에 따른 수정 대응 사전 공지 · Discussion #233 · commerce-api-naver/commerce-api
상품 그룹 내 일부 API 업그레이드 2023년 1월 1일부로 시행되는 「전자상거래 등에서의 상품 등의 정보제공에 관한 고시」 개정안에 맞추어 커머스API [상품] 그룹 내 일부 API가 변경될 예정입니다
github.com
Trace ID
커머스API는 요청마다 Trace ID라는 고유한 ID를 생성하여 관리하고 클라이언트에게 전달합니다. 커머스API 사용에 대한 문의나 문제 상황 확인 요청 시 Trace ID를 전달하면 더 신속한 원인 파악에 도움이 됩니다.
Trace ID는 응답 메시지의 GNCP-GW-Trace-ID 헤더에서 확인할 수 있으며, API 게이트웨이 서버의 오류가 발생한 경우에는 응답 메시지의 traceId 필드에서 확인할 수 있습니다.
1) 인증 토큰 발급
- client_id: 클라이언트 ID (등록한 애플리케이션 ID)
- client_secret: 클라이언트 시크릿 (등록한 애플리케이션 키크릿)
import datetime
import bcrypt
import pybase64, requests, time, json
clientId = "애플리케이션 ID"
clientSecret = "애플리케이션 시크릿"
timestamp = int(round(time.time() * 1000))
# 밑줄로 연결하여 password 생성
password = clientId + "_" + str(timestamp)
# bcrypt 해싱
hashed = bcrypt.hashpw(password.encode('utf-8'), clientSecret.encode('utf-8'))
# base64 인코딩
print(pybase64.standard_b64encode(hashed).decode('utf-8'))
print(timestamp)
<<결과>> 두 줄 출력
A : JDJhJ.................................................VOYXpKNGZLRGpUOENt
B : 1669878315227
API_URL = 'https://api.commerce.naver.com/external'
auth_token_url = f"{API_URL}/v1/oauth2/token"
resp = requests.post(auth_token_url,
data={
'client_id': "애플리케이션 아이디",
'timestamp': "B결과값",
'client_secret_sign': "A 결과값",
'grant_type': 'client_credentials',
'type': 'SELF'
})
print(clientId)
if resp.status_code == 200:
json_data = json.loads(resp.text)
token_=json_data['access_token']
print(token_)
else:
print("False")
토근 결과값 출력