1. 程式人生 > >python模擬登入新浪微博自動獲得呼叫新浪api所需的code

python模擬登入新浪微博自動獲得呼叫新浪api所需的code

其中client_id是我們的APP_KEY;redirect_url是我們的回撥頁面,就是我們一開始建立應用時設定的;regCallback具體我不知道是哪來的,但是其中有兩個變數,一個是APP_KEY,一個就是我們設定的回撥頁面;其它的表單內容都是固定的。請求程式碼如下:
fields={
    'action': 'login',
    'display': 'default',
    'withOfficalFlag': '0',
    'quick_auth': 'null',
    'withOfficalAccount': '',
    'scope': '',
    'ticket': ticket,
    'isLoginSina': '',
    'response_type': 'code',
    'regCallback': 'https://api.weibo.com/2/oauth2/authorize?client_id='+APP_KEY+'&response_type=code&display=default&redirect_uri='+CALLBACK_URL+'&from=&with_cookie=',
    'redirect_uri':CALLBACK_URL,
    'client_id':APP_KEY,
    'appkey62': '52laFx',
    'state': '',
    'verifyToken': 'null',
    'from': '',
    'switchLogin':'0',
    'userId':'',
    'passwd':''
    }
headers = {
    "User-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0",
           "Referer": url,
           "Content-Type": "application/x-www-form-urlencoded"}
post_url='https://api.weibo.com/oauth2/authorize'
get_code_url=requests.post(post_url,data=fields,headers=headers)
最後在從響應成功的get_code_url將code值分析出來即可