Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

CkHttp_put_OAuth1 $http 1
CkHttp_put_OAuthVerifier $http ""
CkHttp_put_OAuthConsumerKey $http "my-consumer-key"
CkHttp_put_OAuthConsumerSecret $http "my-consumer-secret"
CkHttp_put_OAuthToken $http "my-access-token"
CkHttp_put_OAuthTokenSecret $http "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.

set req [new_CkHttpRequest]

CkHttpRequest_AddParam $req "status" "Maybe he'll finally find his keys. #peterfalk"

CkHttpRequest_put_HttpVerb $req "POST"
CkHttpRequest_put_ContentType $req "application/x-www-form-urlencoded"

set resp [new_CkHttpResponse]

set success [CkHttp_HttpReq $http "https://api.twitter.com/1.1/statuses/update.json" $req $resp]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkHttpRequest $req
    delete_CkHttpResponse $resp
    exit
}

if {[CkHttpResponse_get_StatusCode $resp] == 200} then {
    # Display the JSON response.
    puts [CkHttpResponse_bodyStr $resp]
} else {
    puts [CkHttp_lastErrorText $http]
}


delete_CkHttp $http
delete_CkHttpRequest $req
delete_CkHttpResponse $resp