I have problems understanding how to build a http post to acces an api service
I tried using the clarifai api and I make an example , unfortunately I do not understand how it works and how to create proper http statement starting from their documentation
here is my example
Error I got:
hc_response error{"status":{"code":11001,"description":"Invalid authentication token","details":"Invalid Authorization Header"},"outputs":[]}
Thank you
I tried using the clarifai api and I make an example , unfortunately I do not understand how it works and how to create proper http statement starting from their documentation
here is my example
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#BridgeLogger: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
'original content
' curl -X POST \
' -H "Authorization: Key YOUR_API_KEY" \
' -H "Content-Type: application/json" \
' -d '
' {
' "inputs": [
' {
' "data": {
' "image": {
' "url": "https://samples.clarifai.com/metro-north.jpg"
' }
' }
' }
' ]
' }'\
' https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs
Dim job As HttpJob
job.Initialize("myfirstapi",Me)
job.PostString("https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs",$"'{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
}
}
]
}'\"$)
job.GetRequest.SetHeader("Authorization: Key", "YOUR_API_KEY_replaced with my api key")
'job.GetRequest.SetHeader("Content-Type", "application/json")
job.GetRequest.SetContentType("application/json")
job.GetRequest.SetContentEncoding("text/plain")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "myfirstapi"
Log("found a http job:"&Job.Success)
If Job.Success Then
Dim res As String
res = Job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Dim ListOfPO As List
ListOfPO = parser.NextArray
For i=0 To ListOfPO.Size-1
Log(ListOfPO.Get(i))
Next
End If
End Select
End Sub
Error I got:
hc_response error{"status":{"code":11001,"description":"Invalid authentication token","details":"Invalid Authorization Header"},"outputs":[]}
Thank you
Last edited: