Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vReq
    Handle hoReq
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Set ComOAuth1 Of hoHttp To True
    Set ComOAuthVerifier Of hoHttp To ""
    Set ComOAuthConsumerKey Of hoHttp To "my-consumer-key"
    Set ComOAuthConsumerSecret Of hoHttp To "my-consumer-secret"
    Set ComOAuthToken Of hoHttp To "my-access-token"
    Set ComOAuthTokenSecret Of hoHttp To "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.

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Send ComAddParam To hoReq "status" "Maybe he'll finally find his keys. #peterfalk"

    Set ComHttpVerb Of hoReq To "POST"
    Set ComContentType Of hoReq To "application/x-www-form-urlencoded"

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoReq to vReq
    Get pvComObject of hoResp to vResp
    Get ComHttpReq Of hoHttp "https://api.twitter.com/1.1/statuses/update.json" vReq vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 = 200) Begin
        // Display the JSON response.
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
    End
    Else Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
    End



End_Procedure