【问题标题】:Oxford Dictionary API not fetching data after the API migrationAPI 迁移后牛津词典 API 未获取数据
【发布时间】:2019-12-02 19:00:02
【问题描述】:

我在 4 个月前使用过牛津词典 API,它工作得非常好。但是现在当我尝试从 API 获取数据时,它会显示错误。

      "Authentication parameters missing"

我已经根据迁移的 v2 API 更改了 url 请求。

//这是我的日志

"2019-07-24 20:30:41.190 21615-21733/com.example.thereadingapp D/NetworkSecurityConfig:未指定网络安全配置,使用 平台默认 2019-07-24 20:30:45.612 21615-21733/com.example.thereadingapp W/System.err: java.io.FileNotFoundException: https://od-api.oxforddictionaries.com:443/api/v2/lemmas/en/laying 2019-07-24 20:30:45.614 21615-21733/com.example.thereadingapp W / System.err:在 com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) 2019-07-24 20:30:45.621 21615-21733/com.example.thereadingapp W / System.err:在 com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) 2019-07-24 20:30:45.622 21615-21733/com.example.thereadingapp W / System.err:在 com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26) 2019-07-24 20:30:45.624 21615-21733/com.example.thereadingapp W / System.err:在 com.example.thereadingapp.Dictionary.Lemmas.doInBackground(Lemmas.java:41) 2019-07-24 20:30:45.624 21615-21733/com.example.thereadingapp W / System.err:在 com.example.thereadingapp.Dictionary.Lemmas.doInBackground(Lemmas.java:18) 2019-07-24 20:30:45.625 21615-21733/com.example.thereadingapp W/System.err:在 android.os.AsyncTask$2.call(AsyncTask.java:333) 2019-07-24 20:30:45.625 21615-21733/com.example.thereadingapp W / System.err:在 java.util.concurrent.FutureTask.run(FutureTask.java:266) 2019-07-24 20:30:45.625 21615-21733/com.example.thereadingapp W/System.err:
在 android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 2019-07-24 20:30:45.625 21615-21733/com.example.thereadingapp W / System.err:在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 2019-07-24 20:30:45.625 21615-21733/com.example.thereadingapp W / System.err:在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 2019-07-24 20:30:45.627 21615-21733/com.example.thereadingapp W/System.err:在 java.lang.Thread.run(Thread.java:764)"

//调用引理的代码

private void callDictionary(View view){
    Lemmas lemmas = new Lemmas(view);
    lemmas.execute(LemmasURL(word));
}

private String LemmasURL(String string){
    final String language = "en";
    final String word = string;
    final String word_id = word.toLowerCase(); 
    return "https://od-api.oxforddictionaries.com:443/api/v2/lemmas/" + language + "/" + word_id;
}

// asyncTask 中的代码

受保护的字符串 doInBackground(String...strings) {

    try {
        URL url = new URL(strings[0]);
        HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();

        urlConnection.setRequestProperty("Accept","application/json");
        urlConnection.setRequestProperty("app_id",APP_ID);
        urlConnection.setRequestProperty("app_key",APP_KEY);


        BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        StringBuilder stringBuilder = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line + "\n");
        }

        return stringBuilder.toString();

    }

    catch (Exception e) {
        e.printStackTrace();
        return e.toString();
    }
}




@Override
protected void onPostExecute(String s) {
    super.onPostExecute(s);
    try {

    //this code is not working


        JSONObject js = new JSONObject(s);
        JSONArray result = js.getJSONArray("results");


         JSONObject lentries = result.getJSONObject(0);
        JSONArray larray = lentries.getJSONArray("lexicalEntries");




        JSONObject inflexion = larray.getJSONObject(0);
        JSONArray inflectionJSONArray = inflexion.getJSONArray("inflectionOf");

        String theWord = inflectionJSONArray.getString(0);
       //callDefinitionDictionary(getWord(theWord));



    } catch (JSONException e) {
        Log.d(TAG, " Lemmas Feature not working");
    }
}

【问题讨论】:

  • ¿您是否为访问牛津词典 API 付费?

标签: java android json


【解决方案1】:

如果你刚开始:

“缺少认证参数”

向:https://od-api.oxforddictionaries.com:443/api/v2/lemmas/en/laying提出请求

检查您的 API Key 的值是否正确:

   urlConnection.setRequestProperty("app_id",APP_ID);
  urlConnection.setRequestProperty("app_key",APP_KEY);

因为您的 API Key 可能不正确或未启用,请记住现在您必须添加您的信用卡信息to enable de API KEY

【讨论】:

  • 我已登录免费帐户。这是这个错误背后的原因吗
  • 是的,现在您需要设置信用卡信息,以启用 api 密钥。
猜你喜欢
  • 1970-01-01
  • 2014-02-27
  • 2018-11-06
  • 2019-05-22
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-13
相关资源
最近更新 更多