【问题标题】:reply to a twitter direct message with python用python回复推特私信
【发布时间】: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>

【问题讨论】:

标签: python twitter


【解决方案1】:

请在此处查看 Twython 库https://github.com/ryanmcgrath/twython

这里:https://twython.readthedocs.io/en/latest/index.html

寻找可能的解决方案。

【讨论】:

    猜你喜欢
    • 2017-06-19
    • 2012-10-02
    • 2018-12-09
    • 1970-01-01
    • 2012-03-08
    • 2019-01-27
    • 2011-02-11
    • 2012-02-09
    • 2016-10-20
    相关资源
    最近更新 更多