Posting to Twitter from linux command line


#1

I am trying to post a message to my twitter account using the curl command but am having some trouble. Below is the code I am using to post.

curl --request ‘POST’ ‘https://api.twitter.com/1/’ --data ‘status=TEST’ --header ‘Authorization: OAuth
oauth_consumer_key=“13QriTFYmD6ZAfpQLiw3g”, oauth_nonce=“813e8056ccd2585e87d9173f2cf96432”, oauth_signature=“Ckx5%2FQ8ki0h%2F1iR89CLfe4NmNBM%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1369740055”, oauth_token=“631283566-kZGXNkQpYS45woQAu3ecvU9HRja4zS82I2rljxc”, oauth_version=“1.0”’ --verbose

I keep getting a “status: 403 forbidden”

Here is the output. Any help would be appreciated. Thanks.

  • About to connect() to api.twitter.com port 443 (#0)
  • Trying 199.16.156.72… connected
  • Connected to api.twitter.com (199.16.156.72) port 443 (#0)
  • Initializing NSS with certpath: sql:/etc/pki/nssdb
  • CAfile: /etc/pki/tls/certs/ca-bundle.crt
    CApath: none
  • SSL connection using SSL_RSA_WITH_RC4_128_SHA
  • Server certificate:
  • subject: CN=api.twitter.com,OU=Twitter Security,O=“Twitter, Inc.”,L=San Francisco,ST=California,C=US
  • start date: Apr 08 00:00:00 2013 GMT
  • expire date: Dec 31 23:59:59 2013 GMT
  • common name: api.twitter.com
  • issuer: CN=VeriSign Class 3 Secure Server CA - G2,OU=Terms of use at https://www.verisign.com/rpa ©09,OU=VeriSign Trust Network,O=“VeriSign, Inc.”,C=US

POST /1/ HTTP/1.1
User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Host: api.twitter.com
Accept: /
Authorization: OAuth oauth_consumer_key="###################", oauth_nonce="#########################", oauth_signature="####################", oauth_signature_method="########", oauth_timestamp="########", oauth_token="############################", oauth_version="1.0"
Content-Length: 11
Content-Type: application/x-www-form-urlencoded

} [data not shown]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 11 0 41 --:–:-- --:–:-- --:–:-- 41< HTTP/1.1 401 Unauthorized
< cache-control: no-cache, max-age=300
< content-length: 120
< content-type: text/html; charset=utf-8
< date: Tue, 28 May 2013 12:45:42 GMT
< expires: Tue, 28 May 2013 12:50:42 GMT
< server: tfe
< set-cookie: _twitter_sess=XXXXXXX%250ASGFzaHsABjoKQHVzZWR7AA%253D%253D–1164b91ac812d853b877e93ddb612b7471bebc74; domain=.twitter.com; path=/; HttpOnly
< set-cookie: guest_id=v1%XXXX; Domain=.twitter.com; Path=/; Expires=Thu, 28-May-2015 12:45:42 UTC
< status: 401 Unauthorized
< strict-transport-security: max-age=631138519
< vary: Accept-Encoding
< www-authenticate: OAuth realm=“https://api.twitter.com
< x-frame-options: SAMEORIGIN
< x-transaction: 91382dba741cf5b0
< x-ua-compatible: IE=9,chrome=1
< x-xss-protection: 1; mode=block
<
{ [data not shown]

131 120 120 120 0 11 232 21 --:–:-- --:–:-- --:–:-- 430* Connection #0 to host api.twitter.com left intact

  • Closing connection #0
<?xml version="1.0" encoding="UTF-8"?> Timestamp out of bounds /1/

#2
  1. You’re using API v1 – be sure and use v1.1 though it doesn’t support XML. API v1 is deprecated and retiring in June 2013.
  2. Note the timestamp out of bounds error you’re getting. This is due to the oauth_timestamp value in your OAuth. It’s either ahead or behind of Twitter’s clocks. Twitter notes its current understanding of time in our Date HTTP response header.
  3. If you’re getting a HTTP 403 on statuses/update, also examine the response body – does it mention a reason you might have the issue?