Android Question [Solved] How to use this api

Scantech

Well-Known Member
Licensed User
Longtime User
Hey,
We are glad that you have decided to use the OwlBot API.
Your API token is: xxxxxxxx

Here is a sample curl request for you:

curl --header "Authorization: Token xxxxxxxxxxxxxxxx"
https://owlbot.info/api/v4/dictionary/owl -s | json_pp

Good Luck ?

or

[email protected]:~$ curl --header "Authorization: Token <YOUR_TOKEN>" https://owlbot.info/api/v4/dictionary/right -s | json_pp

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:

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.
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
JobName = Dictionary1, Success = true
JobTag = And
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="OwlBot is a free HTTP API for English vocabularies' definitions " />
<meta name="keywords" content="Dictionary, English, API, definition, meaning, pronunciation, dictionary API" />
<meta name="robots" content="noindex">
<meta name="googlebot" content="noindex">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono" rel="stylesheet">
<link id="favicon" rel="icon" href="/static/dictionary/img/favicon.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<title>Error 404 (Not found)?</title>
</head>
<body>
<div class="container">
<div>
<img src="/static/dictionary/img/owlbot.png" style="margin: auto; max-width: 50%; width: 160px; display: block" alt="OwlBot is a free english dictionary API"/>
</div>
<div class="row">
<div class="col-sm-8 offset-sm-2 col-md-6 offset-md-3" style="padding: 40px 0;">
<input type="text" name="word" class="form-control" id="search" style="border-radius: 20px;" placeholder="Try another word ?️"/>
</div>
</div>
<div class="row">
<div class="col-sm-10 offset-sm-1" style="text-align: center">
<img src="/static/dictionary/img/404-photo.png" style="max-width: 100%" />
</div>
</div>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-80200f867-1"></script>
<script>
$('input[type=text]').keypress(function(e){
if(e.which == 13) {
var word = e.target.value;
location.assign("https://owlbot.info/?q="+word);
}
});
var search = document.getElementById("search");
search.focus();
search.select();
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-80200867-1');
</script>
</body>
</html>

without the code " -s | json_pp" i get unsuccessfuly request
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: , Response: {"detail":"Authentication credentials were not provided."}
JobName = Dictionary1, Success = false
JobTag = And
Error: {"detail":"Authentication credentials were not provided."}
 
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.

*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
JobName = Dictionary1, Success = true
JobTag = And
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="OwlBot is a free HTTP API for English vocabularies' definitions " />
<meta name="keywords" content="Dictionary, English, API, definition, meaning, pronunciation, dictionary API" />
<meta name="robots" content="noindex">
<meta name="googlebot" content="noindex">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Ubuntu+Mono" rel="stylesheet">
<link id="favicon" rel="icon" href="/static/dictionary/img/favicon.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<title>Error 404 (Not found)?</title>
</head>
<body>
<div class="container">
<div>
<img src="/static/dictionary/img/owlbot.png" style="margin: auto; max-width: 50%; width: 160px; display: block" alt="OwlBot is a free english dictionary API"/>
</div>
<div class="row">
<div class="col-sm-8 offset-sm-2 col-md-6 offset-md-3" style="padding: 40px 0;">
<input type="text" name="word" class="form-control" id="search" style="border-radius: 20px;" placeholder="Try another word ?️"/>
</div>
</div>
<div class="row">
<div class="col-sm-10 offset-sm-1" style="text-align: center">
<img src="/static/dictionary/img/404-photo.png" style="max-width: 100%" />
</div>
</div>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-80200f867-1"></script>
<script>
$('input[type=text]').keypress(function(e){
if(e.which == 13) {
var word = e.target.value;
location.assign("https://owlbot.info/?q="+word);
}
});
var search = document.getElementById("search");
search.focus();
search.select();
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-80200867-1');
</script>
</body>
</html>
 
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
    capture.png
    37.1 KB · Views: 152
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

Similar Threads

Top