제3자 등록의 미박

1309 단어
제3자 등록의 미박
  • 웨이보 오픈 플랫폼
  • 어플리케이션 등록 및 추가
  • 조인 요청 루트
    #     
    url = 'https://api.weibo.com/oauth2/authorize?'
    #     
    data = {
        'client_id': 'app_key',
        'response_type': 'code', 
        'redirect_uri': 'callback'
    }
    #            ,        ,           
    requst_url = url + urllib.parse.urlencode(data)
  • 리셋 주소에서 코드 값 가져오기
    code = request.query_params.get('code')
  • 사용자 uid와access 가져오기 요청 발송token치
    url = 'https://api.weibo.com/oauth2/access_token?'
    data = {
        'client_id': 'app_key',
        'client_secret': 'app_secret',
         'grant_type': 'authorization_code',
         'code': code,
         'redirect_uri': 'callback'
    }
    #   post  
    msg = requests.post(url,data).text 
    dic_data = json.loads(msg)
    #   uid
    uid = dic_data['uid']
    #   token
    access_token = dic_data['access_token'] 
  • 사용자 세부 정보 얻기
    url = 'https://api.weibo.com/2/users/show.json?'
    data = {
        'access_token':access_token,
        'uid':uid
    }
    #          
    request_url = url + urllib.parse.urlencode(data)
    #     
    data = requests.get(request_url).text
  • 좋은 웹페이지 즐겨찾기