Sample code for 30+ languages & platforms
PowerBuilder

X.com Verfiy Credentials (Deprecated OAuth 1.0a Authentication)

See more X Examples

This is a simple API call to verify that OAuth1.0a authorization is working.

Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not. Use this method to test if supplied user credentials are valid.

X.com historically used OAuth 1.0a for authenticating API requests. However, as of April 2023, Twitter has deprecated OAuth 1.0a and migrated to OAuth 2.0 for most of its API endpoints. This change was part of Twitter's effort to modernize its API and improve security.

That said, if you're working with a legacy system or have access to older documentation, you might still encounter references to OAuth 1.0a.

This example shows how Chilkat could be used with the older/deprecated Twitter v1.1 API calls.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponse
integer li_StatusCode
oleobject loo_Json

li_Success = 0

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Indicate OAuth1.0a authentication is to be used with HTTP requests.
loo_Http.OAuth1 = 1

// Provide OAuth1.0a credentials
loo_Http.OAuthConsumerKey = "X_API_KEY"
loo_Http.OAuthConsumerSecret = "X_API_SECRET"
loo_Http.OAuthSigMethod = "HMAC-SHA1"
loo_Http.OAuthToken = "X_ACCESS_TOKEN"
loo_Http.OAuthTokenSecret = "X_TOKEN_SECRET"
loo_Http.OAuthVerifier = ""

loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://api.twitter.com/1.1/account/verify_credentials.json",loo_SbResponse)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    return
end if

li_StatusCode = loo_Http.LastStatus
if li_StatusCode <> 200 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponse
    return
end if

// We received a successful JSON response.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.LoadSb(loo_SbResponse)
loo_Json.EmitCompact = 0

Write-Debug loo_Json.Emit()


destroy loo_Http
destroy loo_SbResponse
destroy loo_Json