新浪微博python下api的OAuth登陸

2021-06-03 01:42:25 字數 968 閱讀 3975

import webbrowser

import weibopy

from weibopy.auth import oauthhandler

from weibopy.api import api

self.u=user()

def getauth(self):

if len(self.consumer_key)==0:

print("please set consumer_key")

return

if len(self.consumer_secret)==0:

print("please set consumer_secret")

return

return oauthhandler(self.consumer_key,self.consumer_secret)

def getapi(self):

''''''

auth=self.getauth()

auth_url=auth.get_authorization_url()

print('please authorize:'+auth_url)

webbrowser.open(auth_url)

verifier=input('請輸入pin碼:').strip()

auth.get_access_token(verifier)

api=api(auth)

'''網上流傳的是 auth=api(auth.get_access_token(verifier))是錯誤的,

因為api()的引數是oauthhandle物件,這個卡了我好久,害苦我了。

'''return api

if __name__ =='__main__':

for weibo in api.public_timeline():

print(weibo)

Python使用新浪微博API傳送微博的例子

1 註冊乙個新浪應用,得到appkey和secret,以及token,將這些資訊寫入配置檔案sina weibo config.ini,內容如下,僅舉例 複製 如下 userinfo consumer key 8888888888 consumer secret 777777f3feab026050...

新浪微博API的使用

在開發平台可以看見很多微博api 點開微博介面看見下面詳細介面 以獲取最新公共微博為例 獲取當前登入使用者及其所關注使用者的最新微博。parameters since id若指定此引數,則返回id比since id大的微博 即比since id時間晚的微博 預設為0 max id若指定此引數,則返回...

該死的開放API之新浪微博

api 實現不標準還能忍,但是文件不說明清楚,要開發者自己摸索就離譜了。1 我寫這一系列文章的目的就是避免後來者遭同樣的罪。這是第一篇,關於 upload api 的 oauth 驗證失敗問題。去論壇搜尋一下 upload 就知道有多少人深受其害了。2 upload api 的特殊性在於其請求 採用...