欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

12-2 oauth2.0获取微博的access_token

程序员文章站 2023-12-21 18:29:58
...

 

 

 

 

12-2 oauth2.0获取微博的access_token

https://open.weibo.com/wiki/Oauth2/authorize

12-2 oauth2.0获取微博的access_token

 

 

12-2 oauth2.0获取微博的access_token

 


def get_auth_url():
    weibo_auth_url = "https://api.weibo.com/oauth2/authorize"
    redirect_url = "http://47.96.72.197:8000/complete/weibo/"
    auth_url = weibo_auth_url+"?client_id={client_id}&redirect_uri={re_url}".format(client_id=644151125, re_url=redirect_url)

    print(auth_url)


if __name__ == "__main__":
    get_auth_url()

运行,得到一个地址

复制到浏览器访问

12-2 oauth2.0获取微博的access_token

这个浏览器当前没有登录微博。

 

用我的2345浏览器访问,这个浏览器已经登录微博。

12-2 oauth2.0获取微博的access_token

 

点击授权之后

12-2 oauth2.0获取微博的access_token

注意 code

http://47.96.72.197:8000/complete/weibo/?code=47d51aa009c64edaf28515679e2e287d

https://open.weibo.com/wiki/Oauth2/access_token

12-2 oauth2.0获取微博的access_token

 

12-2 oauth2.0获取微博的access_token

 

12-2 oauth2.0获取微博的access_token

获取 token后 看看能不能获取用户基本信息

 

12-2 oauth2.0获取微博的access_token

 

12-2 oauth2.0获取微博的access_token

 

https://open.weibo.com/wiki/2/users/show

 

12-2 oauth2.0获取微博的access_token

 

 

把打印出来的拷贝到浏览器

12-2 oauth2.0获取微博的access_token

 


def get_auth_url():
    weibo_auth_url = "https://api.weibo.com/oauth2/authorize"
    redirect_url = "http://47.96.72.197:8000/complete/weibo/"
    auth_url = weibo_auth_url+"?client_id={client_id}&redirect_uri={re_url}".format(client_id=644151125, re_url=redirect_url)

    print(auth_url)


def get_access_token(code="2f1b9c18a1287709782bcffb3168abe3"):
    access_token_url = "https://api.weibo.com/oauth2/access_token"
    import requests
    re_dict = requests.post(access_token_url, data={
        "client_id":644151125,
        "client_secret":"e195ed0301aa594ce44506e0719c0910",
        "grant_type":"authorization_code",
        "code":code,
        "redirect_uri":"http://47.96.72.197:8000/complete/weibo/"
    })
    pass


def get_user_info(access_token="", uid=""):
    user_url = "https://api.weibo.com/2/users/show.json?access_token={access_token}&uid={uid}".format(access_token=access_token, uid=uid)

    print(user_url)

if __name__ == "__main__":
     # get_auth_url()
    # get_access_token(code="1ddcb0598bb063c06d6c74cf2ad66630")

    # '{"access_token":"2.00zmDGTD0RInah7c5dc81196Gmy","remind_in":"157679999","expires_in":157679999,"uid":"3178356","isRealName":"true"}'
    # '{"access_token":"2.00zmDGTD0RInah7c5dc81196Gmy","remind_in":"157679999","expires_in":157679999,"uid":"3178356","isRealName":"true"}'
    get_user_info(access_token="2.00zmDGTD0RInah7c5dc81196Gmy", uid="3178356777")

 

 

12-2 oauth2.0获取微博的access_token

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

上一篇:

下一篇: