时间:2021-05-22
复制代码 代码如下:
import urllib.parse,os.path,time,sys
from http.client import HTTPSConnection
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
#path
ospath=sys.path[0]
if len(ospath)!=3:
ospath+='\\'
ospath=ospath.replace('\\','/')
#api
class Api:
def sina(self,status,pic):
fSize=os.path.getsize(pic)
BOUNDARY="$-img-lufei-goodboy-$"
CRLF='\r\n'
data=[
#token
'--'+BOUNDARY,
'Content-disposition: form-data; name="access_token"',
'',
'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',#你的access_token
#status
'--'+BOUNDARY,
'Content-disposition: form-data; name="status"',
'',
status,
#pic
'--'+BOUNDARY,
'Content-disposition: form-data; name="pic"; filename="q_17.jpg"',
'Content-type: image/jpeg',
''
]
#utf-8
data=(CRLF.join(data)+CRLF).encode('utf-8')
closing='\r\n--'+BOUNDARY+'--\r\n'
sumlen=len(data)+len(closing)+fSize
#----------------------------------------
h=HTTPSConnection('upload.api.weibo.com')
h.putrequest('POST','/2/statuses/upload.json')
h.putheader('Content-type','multipart/form-data; boundary=%s' % BOUNDARY)
h.putheader('Content-length',sumlen)
h.endheaders()
h.send(data)
f=open(pic,'rb')
while True:
data=f.read(12345)
if not data:
break
h.send(data)
f.close()
h.send(closing.encode('utf-8'))
r=h.getresponse()
return r.read().decode('utf-8','ignore')
api=Api()
#ui
class Dialog(QDialog):
def __init__(self):
super().__init__()
#icon,title
self.setWindowIcon(QIcon(ospath+'weibo.ico'))
self.setWindowTitle('weibo')
#texteditor
self.editor=QTextEdit()
#textline,filebutton,submit
self.line=QLineEdit()
brows=QPushButton('打开')
brows.clicked.connect(self.getFileName)
submit=QPushButton('发表')
submit.clicked.connect(self.submit)
#layout
layout=QGridLayout()
layout.setContentsMargins(0,0,0,0)
#addwidget
layout.addWidget(self.editor,0,0,1,2)
layout.addWidget(self.line,1,0,1,1)
layout.addWidget(brows,1,1,1,1)
layout.addWidget(submit,2,0,1,2)
#set
self.setLayout(layout)
def getFileName(self):
fileName=QFileDialog.getOpenFileName()
self.line.setText(fileName[0])
def submit(self):
status=self.editor.toPlainText()
pic=self.line.text()
self.editor.setText(api.sina(status,pic))
app=QApplication(sys.argv)
dialog=Dialog()
dialog.show()
app.exec_()
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
微博上传图片失败的原因有: 1、上传的图片的格式新浪微博不支持,新浪微博支持的格式有:JPG、GIF、PNG。 2、上传的图片太大,新浪微博头像图片不能大于
今天下了个新浪微博的API研究研究,目前实现了发布微博功能,包括带图片的微博。为了安全,新浪微博的API中并没有提供用微博帐号密码登录的功能,而是采用OAuth
坚信近期很多人都被新浪微博的全景图片给震撼到吧。那麼,新浪微博全景图片是如何制作公布的呢?下边大家来一起看一下新浪微博全景图片具体步骤方式流程吧。新浪微博全景图
现在玩微博的人越来越多了,而关于微博的第三方应用开发也越来越多,自己在偶然间开始接触了新浪微博API开发,新浪微博API开发的资源比较多,新浪微博提供了一个开发
本文仅供学习交流,请勿用于商业用途,并遵守新浪微博相关规定。代码目录此微博机器人的实现功能如下:模拟登陆新浪微博,获取cookie;自动上传图片至微博图床;自动