Go
Go
WhatsApp - Get a User's Account Information
Demonstrates how to retrieve a user account by sending a GET request on the users endpoint.Chilkat Go Downloads
success := false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := chilkat.NewHttp()
// Implements the following CURL command:
// curl -X GET https://example.com/v1/users/username \
// -H "Authorization: Bearer your-auth-token"
// Adds the "Authorization: Bearer your-auth-token" header.
http.SetAuthToken("your-auth-token")
sbResponseBody := chilkat.NewStringBuilder()
success = http.QuickGetSb("https://example.com/v1/users/username",sbResponseBody)
if success == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
return
}
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := http.LastStatus()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(http.LastHeader())
fmt.Println("Failed.")
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
return
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "users": [
// {
// "ROLES": "ROLE_ADMIN | ROLE_USER",
// "username": "username"
// }
// ]
// }
// Sample code for parsing the JSON response...
var ROLES *string = new(string)
var username *string = new(string)
i := 0
count_i := jResp.SizeOfArray("users")
for i < count_i {
jResp.SetI(i)
ROLES = jResp.StringOf("users[i].ROLES")
username = jResp.StringOf("users[i].username")
i = i + 1
}
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()