2016-04-29 292 views
1

是否可以使用CURL將twitter消息發送給Twitter的追隨者?我可以在帳戶之間手動DM。這是我第一次進入twitter應用程序開發,所以任何幫助將不勝感激。使用curl發送Twitter直接消息

我想在我的系統-usernames /密碼下面的命令是出演了:

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): 

回答

1

呀及其可能

下面是cURL命令,我剛剛嘗試過,它的工作。

curl --request 'POST' 'https://api.twitter.com/1.1/direct_messages/new.json' --data 'screen_name=(TWITTER ID)&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的人關注你的)

+0

感謝您的,但似乎生成的密鑰是一錘子擊中一兩分鐘後到期。我需要一些我可以隨時重複使用並自動化的東西。 – user2699504

+0

生病嘗試一種新的方法我自己,並得到回覆 –

+0

嘗試ysing temboo api。打我一個大拇指upvif你喜歡的答案 –

相關問題