【问题标题】:Send Twitter Direct Message using curl使用 curl 发送 Twitter 直接消息
【发布时间】:2016-04-29 23:27:42
【问题描述】:

是否可以仅使用 CURL 向 Twitter 中的关注者发送 DM 消息。我可以在帐户之间手动 DM。这是我第一次涉足 Twitter 应用程序开发,因此我们将不胜感激。

我在我的系统上尝试了以下命令 - 用户名/密码被加星标:

curl  --insecure --verbose  --user *****:***** 
--data "text=hello_world&screen_name=***"    
https://api.twitter.com/1.1/direct_messages/new.json

并收到如下回复:

* About to connect() to api.twitter.com port 443 (#0)
*   Trying 199.16.156.231... connected
* Connected to api.twitter.com (199.16.156.231) port 443 (#0)
* libcurl is now using a weak random seed!
* SSLv2, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES128-SHA
* Server certificate:
*        subject: C=US, ST=California, L=San Francisco, O=Twitter, Inc., OU=Twitter Security, CN=api.twitter.com
*        start date: 2014-08-03 00:00:00 GMT
*        expire date: 2016-12-31 23:59:59 GMT
*        subjectAltName: api.twitter.com matched
*        issuer: C=US, O=VeriSign, Inc., OU=VeriSign Trust Network, OU=Terms of use at https://www.verisign.com/rpa (c)10, CN=VeriSi
gn Class 3 Secure Server CA - G3
*        SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Server auth using Basic with user '********'
> POST /1.1/direct_messages/new.json HTTP/1.1
> Authorization: Basic dGF1cGlyaG86c3ltbWV0cnkz
> User-Agent: curl/7.19.5 (IA64-HP-VMS) libcurl/7.19.5 OpenSSL/0.9.7d
> Host: api.twitter.com
> Accept: */*
> Content-Length: 32
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 400 Bad Request
< content-length: 62
< content-type: application/json; charset=utf-8
< date: Fri, 29 Apr 2016 09:37:05 GMT
< server: tsa_b
< set-cookie: guest_id=v1%3A146192262515114070; Domain=.twitter.com; Path=/; Expires=Sun, 29-Apr-2018 09:37:05 UTC
< strict-transport-security: max-age=631138519
< x-connection-hash: dcb0fd08d7bd0a64a0be40c7552ee0de
< x-response-time: 5
< x-tsa-request-body-time: 0
<
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
                                                              * Connection #0 to host api.twitter.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

【问题讨论】:

    标签: curl twitter message


    【解决方案1】:

    是的,有可能

    下面是我刚刚尝试过的 cURL 命令,它成功了。

     curl --request 'POST' 'https://api.twitter.com/1.1/direct_messages/new.json' --data 'screen_name=(TWITTER ID)&amp;text=hello%2C+tworld.+welcome+to+1.1.' --header 'Authorization: OAuth oauth_consumer_key="**********************", oauth_nonce="**********************", oauth_signature="******************", oauth_signature_method="HMAC-SHA1", oauth_timestamp="****************", oauth_token="****************************", oauth_version="1.0"' --verbose

    确保您在apps.twitter.com 上创建了一个应用,您可以将网站设为http://example.com

    然后转到密钥和访问令牌选项卡并生成令牌访问权限。

    然后转到This Page 并向下滚动到 OAuth 签名生成器,选择您的应用程序,您将被重定向到另一个页面。确保所有 OAuth 设置都填充了一些随机令牌和密钥。前往页面并生成 OAuth 签名,您将获得一个 cURL 代码,将其发布到终端中,瞧!

    确保您编辑 RequestQuery screen_name=(关注您的人的 TWITTER id)

    【讨论】:

    • 谢谢你,但似乎生成的键是一两分钟后过期的一次性点击。我需要一些可以一直重复使用并自动化的东西。
    • 我自己尝试一种新方法并回复您
    • 尝试使用 temboo api。如果你喜欢这个答案,请给我竖起大拇指
    猜你喜欢
    • 2020-07-14
    • 2012-02-09
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 2020-05-01
    • 2020-09-10
    • 2012-05-02
    • 2015-02-23
    相关资源
    最近更新 更多