【发布时间】:2016-05-03 22:45:31
【问题描述】:
我正在尝试编写一个程序来回复发送特定直接消息的用户。我对python很陌生,因此非常感谢任何帮助或建议。非常感谢,这是我的代码:
from twitter import *
import time
#Sets up twitter library
from twitter import *
access_token = 'replaced'
access_token_secret = 'with'
consumer_key = 'this'
consumer_secret = 'stuff'
twitter_api = Twitter(auth=OAuth(access_token, access_token_secret, consumer_key, consumer_secret))
twitter_userstream = TwitterStream( domain='userstream.twitter.com')
for msg in twitter_userstream.user():
if 'weather' in msg:
twitter_api.direct_messages.new(user=user, text='here is your current weather update.')
else:
twitter_api.direct_messages.new(user=user, text="That is not an acceptable request, try entering 'weather.'")
这是它提出的 401 错误:
for msg in twitter_userstream.user():
File "build/bdist.linux-armv7l/egg/twitter/api.py", line 312, in __call__
File "build/bdist.linux-armv7l/egg/twitter/stream.py", line 284, in _handle_response
File "build/bdist.linux-armv7l/egg/twitter/stream.py", line 209, in handle_stream_response
twitter.api.TwitterHTTPError: Twitter sent status 401 for URL: 1.1/user.json using parameters: (None)
details: <html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/user.json'. Reason:
<pre> Unauthorized</pre>
</body>
</html>
【问题讨论】:
-
我只想在这里指出,因为这在 Google 搜索结果中很重要,所以这个 repo 没有被更新以适应 Twitter API 对 DM 的更改:github.com/sixohsix/twitter/issues/382