POST-ing a tweet using libcurl and liboauth in C


#1

I’m trying to post a tweet to "https://api.twitter.com/1.1/statuses/update.json?" using libcurl and liboauth in C. I can get tweets, using the following code:

char *url = "https://api.twitter.com/1.1/statuses/home_timeline.json"; 
char *signedurl = oauth_sign_url2(url, NULL, OA_HMAC, "GET", consumer_key, consumer_secret, user_token, user_secret);

curl_easy_setopt(curl, CURLOPT_URL, signedurl);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "user-string"); /* Dummy string */
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_memory);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&response);
    
int curlstatus = curl_easy_perform(curl); 

I can also verify the account credential using “https://api.twitter.com/1.1/account/verify_credentials.json”. However, when I try to post tweets, with the following, similar, code:

char *signedurl = malloc(sizeof(char) * 2048); /*Not actually how it is, but works in this code fragment */
char *url = "https://api.twitter.com/1.1/statuses/update.json?";
signedurl = oauth_sign_url2(url, NULL, OA_HMAC, "POST", consumer_key, consumer_secret, user_token, user_secret);
char *status = oauth_url_escape("status=test");

curl_easy_setopt(curl, CURLOPT_URL, signedurl); /* URL we're connecting to, after being signed by oauthlib */
curl_easy_setopt(curl, CURLOPT_USERAGENT, "user-string"); /* Dummy string */
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, status);
    
int curlstatus = curl_easy_perform(curl); /* Execute the request! */

I recieve the error message: “{“errors”:[{“message”:“Could not authenticate you”,“code”:32}]”

I’ve tried following the instructions at the FAQ, i.e. regenerate the access tokens, escape the strings and the correct header is used by libcurl, I’m fairly certain of.

What am I doing wrong?