小编cod*_*ina的帖子

为推特注册 webhook 的程序是什么?

我正在尝试通过 twitter 文档中给出的 curl 命令将 url 注册为 twitter 上的 webhook。我认为 Twitter 文档有点过时或不正确。

 curl --request POST --url "https://api.twitter.com/1.1/account_activity/all/prod/webhooks.json?url=https%3A%2F%2FXXXX.com%2Fwebhook%2Ftwitter" --header "authorization: OAuth oauth_consumer_key='XXXXXXXXXXXXXXXXXXXXXX', oauth_nonce='ODgyNjc5NjQ0MTM3NzI4NTcwMjY4NDQ0', oauth_signature='7daMyzB1JClE4xv8hXNCimWpGtA%3D', oauth_signature_method='HMAC-SHA1', oauth_timestamp='1568620293', oauth_token='XXXXXXXXXXXXXXXXXXXXX', oauth_version='1.0'"
Run Code Online (Sandbox Code Playgroud)

运行此代码后,我收到错误

{"errors":[{"code":215,"message":"Bad Authentication data."}]}
Run Code Online (Sandbox Code Playgroud)

下面给出了我用来生成时间戳、oauth_nonce、oauth_signature 的代码。这些代码在python3中。我不太确定他们是否给出了正确的输出。

oauth_timestamp = str(int(time.time()))


#oauth_nonce
def get_nonce():
    nonce = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits)for x in range(32))
return nonce


#oauth_signature

def escape(s):
"""Percent Encode the passed in string"""
    return urllib.parse.quote_plus(s, safe='~')


def create_auth_header(parameters):
"""For all collected parameters, order them and create auth header"""
    ordered_parameters = {}
    ordered_parameters = …
Run Code Online (Sandbox Code Playgroud)

webhooks python-3.x twitterapi-python

1
推荐指数
1
解决办法
910
查看次数

标签 统计

python-3.x ×1

twitterapi-python ×1

webhooks ×1