Sample code for 30+ languages & platforms
Unicode C

Twitter OAuth -- Tweet to Your Own Account

See more HTTP Examples

Demonstrates how to send a tweet (status update) to your own Twitter account using pre-known credentials, which includes:

  1. Consumer Key
  2. Consumer Secret
  3. Access Token
  4. Token Secret

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkHttpRequestW req;
    HCkHttpResponseW resp;

    success = FALSE;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    CkHttpW_putOAuth1(http,TRUE);
    CkHttpW_putOAuthVerifier(http,L"");
    CkHttpW_putOAuthConsumerKey(http,L"my-consumer-key");
    CkHttpW_putOAuthConsumerSecret(http,L"my-consumer-secret");
    CkHttpW_putOAuthToken(http,L"my-access-token");
    CkHttpW_putOAuthTokenSecret(http,L"my-token-secret");

    // Send the same status update as shown in this example:
    // https://dev.twitter.com/docs/api/1.1/post/statuses/update

    // IMPORTANT: Make sure this app has read/write access.  
    // Otherwise it cannot post an update (i.e. tweet) to the Twitter account.

    req = CkHttpRequestW_Create();
    CkHttpRequestW_AddParam(req,L"status",L"Maybe he'll finally find his keys. #peterfalk");

    CkHttpRequestW_putHttpVerb(req,L"POST");
    CkHttpRequestW_putContentType(req,L"application/x-www-form-urlencoded");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpReq(http,L"https://api.twitter.com/1.1/statuses/update.json",req,resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    if (CkHttpResponseW_getStatusCode(resp) == 200) {
        // Display the JSON response.
        wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    }
    else {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
    }



    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);
    CkHttpResponseW_Dispose(resp);

    }