12-2 oauth2.0获取微博的access_token
程序员文章站
2023-12-21 18:29:58
...
https://open.weibo.com/wiki/Oauth2/authorize
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()
运行,得到一个地址
复制到浏览器访问
这个浏览器当前没有登录微博。
用我的2345浏览器访问,这个浏览器已经登录微博。
点击授权之后
注意 code
http://47.96.72.197:8000/complete/weibo/?code=47d51aa009c64edaf28515679e2e287d
https://open.weibo.com/wiki/Oauth2/access_token
获取 token后 看看能不能获取用户基本信息
https://open.weibo.com/wiki/2/users/show
把打印出来的拷贝到浏览器
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")
推荐阅读
-
java调用新浪长连接转短链接api--新浪微博Oauth2.0授权 获取Access Token
-
12-2 oauth2.0获取微博的access_token
-
微信公众平台获取access_token的方法步骤
-
使用java代码获取新浪微博应用的access token代码实例
-
Python 获取新浪微博的最新公共微博实例分享
-
微信公众平台获取access_token的方法步骤
-
C#微信公众平台开发之access_token的获取存储与更新
-
PHP cURL获取微信公众号access_token的实例
-
Python 获取新浪微博的最新公共微博实例分享
-
[IOS]——获取新浪微博的.json数据