Chilkat Online Tools

PureBasic / Broker API / client_id

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "{{api_key}}")
    CkHttp::setCkPassword(http, "{{api_secret}}")

    ; Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    ; The following JSON is sent in the request body.

    ; {
    ;   "response_type": "token",
    ;   "redirect_uri": "www.example.com/oauth_redirect",
    ;   "scope": "general"
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"response_type","token")
    CkJsonObject::ckUpdateString(json,"redirect_uri","www.example.com/oauth_redirect")
    CkJsonObject::ckUpdateString(json,"scope","general")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"GET","https:///v1/oauth/clients/:client_id",sbRequestBody,"utf-8","application/json",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-u '{{api_key}}:{{api_secret}}'
	-d '{
  "response_type": "token",
  "redirect_uri": "www.example.com/oauth_redirect",
  "scope": "general"
}'
https:///v1/oauth/clients/:client_id

Postman Collection Item JSON

{
  "name": "client_id",
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"response_type\": \"token\",\n  \"redirect_uri\": \"www.example.com/oauth_redirect\",\n  \"scope\": \"general\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "/v1/oauth/clients/:client_id",
      "path": [
        "v1",
        "oauth",
        "clients",
        ":client_id"
      ],
      "variable": [
        {
          "key": "client_id",
          "value": null
        }
      ]
    },
    "description": "| Attribute         | Type   | Notes                                  |\n| ----------------- | ------ | -------------------------------------- |\n| `response_type`   | string | ENUM: `code` or `token`                |\n| `redirect_uri`    | string | Redirect URI of the OAuth flow         |\n| `scope`           | string | Requested scopes by the OAuth flow     |"
  },
  "response": [
  ]
}