我正在尝试使用Python的HTTPSConnection
读取Twitter用户流。我可以成功地连接并授权到Twitter的API,但是,当我从web站点发tweet时,没有其他东西被推送到流中。我的代码在下面。你知道吗
import http.client
#Authorization headers cut
authheaders = """OAuth oauth_consumer_key="<snip>", oauth_nonce="<snip>", oauth_signature="<snip>", oauth_signature_method="<snip>", oauth_timestamp="<snip>", oauth_token="<snip>", oauth_version="1.0" """
conn = http.client.HTTPSConnection("userstream.twitter.com:443")
conn.putrequest("GET", "/1.1/user.json")
conn.putheader("Authorization", authheaders)
conn.endheaders()
resp = conn.getresponse()
print("HTTP " + str(resp.status))
while True:
buff = resp.read(8192)
if buff != b'':
print(buff)
结果我一次读的数据太多了。通过将
buff = resp.read(8192)
更改为buff = resp.read(1024)
,我现在可以阅读我的tweet了。你知道吗相关问题 更多 >
编程相关推荐