获取新浪微博api授权

本文介绍如何使用微博API进行授权操作,包括申请应用获得AppKey和AppSecret,通过授权页面获取code,最后利用code请求AccessToken的过程。
1、申请应用,申请应用成功后有下面两个
App Key:
App Secret:


2、获取code,参数:
client_id=App Key
redirect_uri=站内地址
response_type=code


https://api.weibo.com/oauth2/authorize?client_id=XXX&redirect_uri=XXX&response_type=code


返回的url
http://apps.weibo.com/yanjieclawer?code=XXX


3、通过code获取Access Token
client_id=App Key
client_secret=XXX
grant_type=authorization_code
redirect_uri=站内地址
code=XXX


但是不能用get方式
https://api.weibo.com/oauth2/access_token?client_id=XXX&client_secret=XXX&grant_type=authorization_code&redirect_uri=XXX&code=XXX


通过python编写post请求


def get_key(client_id=None,client_secret=None,grant_type=None,redirect_uri=None,code=None):
    url = "https://api.weibo.com/oauth2/access_token"
    postdata = dict(client_id=client_id, client_secret=client_secret, grant_type=grant_type, redirect_uri=redirect_uri,
                    code=code)
    r = requests.post(url, data=postdata)
    print(r.text)


得到access token
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值