-1

i'm trying to connect my Cordova project at the API of Oxford Dictionnary api for building an application. I just need to return an array on JSON with this request. https://developer.oxforddictionaries.com/documentation

I need a server request for call the API. Then I download a plugin in cordova, it's "cordova-plugin-http-advanced" but I have two problems when i'm trying to call the API.

Cannot read property 'http' of undefined

cordova.plugin.http.get('https://od-api.oxforddictionaries.com/api/v1', {
     source_lang: "en",
     word_id: "ace",
     app_id: "xxxxxx",
     app_key: "xxxxxxxxxxxx"
}, { Authorization: 'OAuth2: ???' }, function(response) {
     console.log(response.status);
}, function(response) {
   console.error(response.error);
});

And my second problem is in the Authorization case, what I need to write ? My app_key ?

Thx for the helping

Index.html

<!DOCTYPE html>
<html>
  <head>
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user- 
     scalable=no">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script type="text/javascript" src="cordova.js"></script>
    <title>Oxford Dictionnary</title>

  </head>
  <body>
    <!-- CONSOLE.LOG FOR LOOKING FOR THE OBJECT RETURN IN JS -->
    <script type="text/javascript" src="js/index.js"></script>
  </body>
</html>

1 Answers1

0

Usually cordova is not defined when the application doesn't wait for deviceready event, this can happen when your application bootstrapped before this event or you don't have the script tag in your index.html ( or you have the quotes issue deviceready Event not fired in an Angular hybrid app )

Can you post your index.html? Which js framework are you using?

Sergio Rinaudo
  • 2,303
  • 15
  • 20
  • I switch the cordova.js in the head and your right, this working, but I have again a new problem on the http. I post my index.html and i'm just using Cordova – Paulo Wllier Feb 04 '19 at 10:10
  • Script tag for cordova.js should not be moved from the body, in your application you should wait for the deviceready event. For the plugin just check if it is correctly installed, if the error persist my advice is to use fetch js API ( https://gist.github.com/justsml/529d0b1ddc5249095ff4b890aad5e801 ) – Sergio Rinaudo Feb 04 '19 at 11:00