Twitter POST 404 error to my DailyBirdBreath account


#1
curl --request 'POST' 'https://api.twitter.com/1.1/' -d status="Here's your new weekday BirdBreath cartoon for $month $day, $year" --header 'Authorization: OAuth oauth_consumer_key="TcrdUlDdg8id1ZYjdXg", oauth_nonce="190a4cdab0fe75cabf5b9267a0f04ebb", oauth_signature="Np3DCSRPpGCPO62kxocEx6BpBUU%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1429803013", oauth_token="50180715-3F7yZmwBLJouO3fa6avhW0AJG0d7Y9bfMpRWYQEkQ", oauth_version="1.0"' --verbose

When trying to post to my DailyBirdBreath Twitter account, it returns this without posting my status. Any ideas why?

Robert Seymour

sh tweet-test.sh

Sorry, that page doesn’t exist!


#2

https://api.twitter.com/1.1/' is the base URL for the REST API but you are missing the path. For POST statuses/update you’ll want https://api.twitter.com/1.1/statuses/update.json.


#3

Thanks Abraham for the fast response.

Now however I’m getting a variety of errors. It appears I have too many parameters.

What is the minimum curl command I need to Post?


#4

I would recommend against using OAuth in curl. OAuth is pretty complex and manually doing anything with it is asking for all kinds of issues.


#5

I understrand. But what would be the minimum curl command I could use? Consumer key and Consumer secret?


#6

Look at “OAuth Signature Generator” for GET account/verify_credentials and it will generate a curl command for you.


#7

Here is what it generated:

curl --request ‘POST’ ‘https://stream.twitter.com/1.1/statuses/filter.json’ --data ‘track=twitter’ --header ‘Authorization: OAuth oauth_consumer_key=" TcrdUlDdg8id1ZYjdXg ", oauth_nonce=“27”, oauth_signature=“rj3pZolYkKeCxdyhYriZqgouGKo%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1429896973”, oauth_token=“50180715-3F7yZmwBLJouO3fa6avhW0AJG0d7Y9bfMpRWYQEkQ”, oauth_version=“1.0”’ --verbose

Here is what it returned:

  • SSL certificate verify ok.

POST /1.1/statuses/filter.json HTTP/1.1
User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Host: stream.twitter.com
Accept: /
Authorization: OAuth oauth_consumer_key=" TcrdUlDdg8id1ZYjdXg ", oauth_nonce=“27”, oauth_signature=“rj3pZolYkKeCxdyhYriZqgouGKo%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1429896973”, oauth_token=“50180715-3F7yZmwBLJouO3fa6avhW0AJG0d7Y9bfMpRWYQEkQ”, oauth_version=“1.0”

Content-Length: 13
Content-Type: application/x-www-form-urlencoded

track=twitterHTTP/1.1 401 Authorization Required
< cache-control: must-revalidate,no-cache,no-store
< connection: close
< content-length: 266
< content-type: text/html
< date: Fri, 24 Apr 2015 17:56:13 GMT
< server: tsa
< www-authenticate: OAuth realm=“Firehose”
< x-connection-hash: b39d590e84763daef7dd58ac25493e02

\n\n\nError 401 Unauthorized

HTTP ERROR: 401

Problem accessing '/1.1/statuses/filter.json'. Reason:

    Unauthorized
* Closing connection #0 * SSLv3, TLS alert, Client hello (1):

#8

The statuses/filter stream worked fine for my generated signature. Keep in mind that OAuth requests are timestamped and last I knew only good for about 5 minutes.


#9

You should try to use twurl instead of curl, as it handles OAuth for you.


#10

I am on MidPhase. I do not have root or install privileges.

What simple method do you recommend I use to post to Twitter daily in a cron job?


#11

twurl


#12

Thanks for all your help.
Used Net::Twitter 4.01010
Works great

#!/usr/bin/perl
#Script twitter1.pl
#Written by Robert Seymour

#Script emails daily BB cartoon

#Script sends emailed cartoons to subscribers

@months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
@days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$year += 1900;
 print "$mday $months[$mon] $year\n";

 $status = "Here is your new weekday BirdBreath cartoon for $mday $months[$mon] $year";

 my $tweet = $status;
 my $twitterconsumer = "xxx";
 my $twitterconsumersecret = "xxx";
 my $twitteraccesstoken = "xxx";
 my $twitteraccesstokensecret = "xxx";

 use Net::Twitter;

     my $nt = Net::Twitter->new(
         traits              => [qw/API::RESTv1_1/],
         consumer_key        => $twitterconsumer,
         consumer_secret     => $twitterconsumersecret,
         access_token        => $twitteraccesstoken,
         access_token_secret => $twitteraccesstokensecret,
     );

 #troubleshooting
 print $twitterconsumer."\r\n";
 print $twitterconsumersecret."\r\n";
 print $twitteraccesstoken."\r\n";
 print $twitteraccesstokensecret."\r\n";

#13

Please indent code with 4 spaces or use fenced code blocks so it will display readable.


#14

Thanks iPirat