Sample code for 30+ languages & platforms
PowerBuilder

Explicitly set the OAuth2 Access Token

This example shows how to set the AuthToken property using a previously obtained access token.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Json
oleobject loo_Http

li_Success = 0

// Assume we previously obtained JSON containing the access token such as this:

// 	{
// 	 "access_token": "ya39.Ci-XA_C5bGgRDC3UaD-h0_NeL-DVIQnI2gHtBBBHkZzrwlARkwX6R3O0PCDEzRlfaQ",
// 	 "token_type": "Bearer",
// 	 "expires_in": 3600,
// 	 "refresh_token": "1/r_2c_7jddspcdfesrrfKqfXtqo08D6Q-gUU0DsdfVMsx0c"
// 	}
// 

// Load the JSON and use the access_token to authenticate an HTTP request.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_Json
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Json.LoadFile("c:/someDir/tokens/myToken.json")

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

// After setting this property, all HTTP requests sent using this object instance
// will include the request header: Authorization: Bearer <access_token> 
loo_Http.AuthToken = loo_Json.StringOf("access_token")

// ...
// ..


destroy loo_Json
destroy loo_Http