0

I am trying to implement twinword word dictionary API on Android Studio. The error message I got is:

I/OkHttpClient: Callback failure for call to https://twinword-twinword-bundle-v1.p.rapidapi.com/...
    java.io.IOException: Unexpected code Response{protocol=http/1.1, code=403, message=Forbidden, url=https://twinword-twinword-bundle-v1.p.rapidapi.com/word_example/?entry=mask}
        at com.example.anew.SentenceFramer$1.onResponse(SentenceFramer.java:58)
        at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
        at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:760)

I believe the message is forbidden because it cannot access the rapidAPI and I think the problem is I couldn't figure out what is the Project Key as I couldn't find it anywhere in RapidAPI website. Or does the problem actually lies in my codes?

RapidApiConnect connect = new RapidApiConnect("I put my project name here", "I dont know where to find project key");
String object_1;

String host = "twinword-twinword-bundle-v1.p.rapidapi.com";
String API_KEY = "this is the api key";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sentence_framer);

    object_1 = getIntent().getStringExtra("First Object");
    Log.d("EDMTERROR", object_1);
    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
            .url("https://twinword-twinword-bundle-v1.p.rapidapi.com/word_example/?entry=mask")
            .get()
            .addHeader("x-rapidapi-host", host)
            .addHeader("x-rapidapi-key", API_KEY)
            .build();

    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            Log.d("EDMTERROR", "onfailure");
            e.printStackTrace();
        }

        @Override
        public void onResponse(Response response) throws IOException {
            Log.d("EDMTERROR", "masalah");

            try (ResponseBody responseBody = response.body()) {
                if (!response.isSuccessful()) {
                    Log.d("EDMTERROR", "unexpected code");
                    throw new IOException("Unexpected code " + response);
                }

                Headers responseHeaders = response.headers();
                Log.d("EDMTERROR", "headers");
                for (int i = 0, size = responseHeaders.size(); i < size; i++) {

                    System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
                }

                System.out.println(responseBody.string());
            }

This is my first time doing this, so I haven't got the slightest clue on how to fix this. The website Im trying to reach is https://rapidapi.com/twinword/api/word-dictionary?endpoint=53aa5089e4b0a798dbd1a61d.

Please help, I need this for my final year project...

Grokify
  • 15,092
  • 6
  • 60
  • 81

1 Answers1

0

It's looks like you haven't subscribed to the API on rapidapi.com (https://rapidapi.com/twinword/api/word-dictionary/pricing)

also, I couldn't find the endpoint you are trying to use (/word_example), looks like the right endpoint is /example.

You can always contact them at support@rapidapi.com

  • it seems that RapidAPI has problems with its own API, so I have to create my own class to duplicate the API. Regardless, thank you so much for replying – Rifa'i Khuzairy Jan 21 '20 at 00:07