Android Question [Solved] How to use this api

Scantech

Well-Known Member
Licensed User
Longtime User

B4X:
Sub Dictionary1 (jobnamekey As String, Word As String)
    Dim job As HttpJob

    Dim word_id As String = Word
    Dim jobname As String = jobnamekey
    Dim jobtag As String = Word
    Dim app_id As String = SourceKey1  '    "Authorization: Token " & SourceKey1
    job.Initialize(jobname, Me)
    job.Tag = jobtag

    Dim poststr As String = "https://owlbot.info/api/v4/dictionary/" & word_id & " -s | json_pp"
    job.Download(poststr)

    job.GetRequest.Setheader("Accept", "application/json")
    job.GetRequest.SetHeader("Token", app_id)
    job.GetRequest.SetContentEncoding("text/plain")

End Sub

Not sure how to set in the header and the url address to request. I have been trying many different headers and address to get it going but no luck.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
I think
B4X:
"-s | json_pp”
is not required.

Try
job.GetRequest.SetHeader(“Content-Type”, “application/json")
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
I think
B4X:
"-s | json_pp”
is not required.

Try
job.GetRequest.SetHeader(“ContentType”, “application/json")

With the code " -s | json_pp" I get successfuly request but no data for definition.

without the code " -s | json_pp" i get unsuccessfuly request
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try
B4X:
 job.GetRequest.SetHeader("Token", app_id)
change to
B4X:
job.GetRequest.SetHeader("Authorization", "Bearer " & app_id)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the url appears correct, based on owbot api's docs, but it is the strangest-looking i've seen. spaces and that "|" are very unusual. if you keep the spaces, they will have to be urlencoded ("%20"). if you use a browser to make the request, it automatically does the encoding. when you use okhttputils, you'll have to handle it yourself.

as for your authorization, it's job.GetRequest.SetHeader("Authorization", "Bearer " & yourtoken) you have SetHeader("Token" ...). Also, owlbot seems to want
the word "Token" instead of "Bearer". they are the same; "Bearer" is part of the original spec. see which one works.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Changed it. Still no result.

 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Tried
B4X:
job.GetRequest.SetHeader("Authorization", "Token " & app_id)

and
B4X:
job.GetRequest.SetHeader("Authorization", "Bearer " & app_id)

Both no good results
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
here. this works. look carefully at the url. on the right side you can see the json i got back.
the url shown by owlbot is funny.
 

Attachments

  • capture.png
    37.1 KB · Views: 213
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Dictionary1 (jobnamekey As String, Word As String)
    Dim job As HttpJob
 
    Dim word_id As String = Word
    Dim jobname As String = jobnamekey
    Dim jobtag As String = Word
    Dim app_id As String = SourceKey1  '    "Authorization: Token " & SourceKey1
    job.Initialize(jobname, Me)
    job.Tag = jobtag

'    Log(SourceKey1)

    Dim poststr As String = "https://owlbot.info/api/v4/dictionary/" & word_id  
    Log(poststr)
    
    job.Download(poststr)
    
    job.GetRequest.Setheader("Accept", "application/json")
    job.GetRequest.SetHeader("Authorization", "Token " & app_id)
    job.GetRequest.SetContentEncoding("text/plain")
    
End Sub

Yes, it works. Thanks both of you for your help. I thought I tried this option earlier but i guess i did not.
 
Upvote 0