简体   繁体   English

尝试在 Android Studio 上实现 RapidApi

[英]Trying to implement RapidApi on Android Studio

I am trying to implement twinword word dictionary API on Android Studio.我正在尝试在 Android Studio 上实现双字词词典 API。 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.我认为该消息是被禁止的,因为它无法访问 RapidAPI,我认为问题是我无法弄清楚项目密钥是什么,因为我在 RapidAPI 网站的任何地方都找不到它。 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 .我试图访问的网站是https://rapidapi.com/twinword/api/word-dictionary?endpoint=53aa5089e4b0a798dbd1a61d

Please help, I need this for my final year project...请帮忙,我的最后一年项目需要这个...

It's looks like you haven't subscribed to the API on rapidapi.com ( https://rapidapi.com/twinword/api/word-dictionary/pricing )您似乎还没有在 Rapidapi.com ( https://rapidapi.com/twinword/api/word-dictionary/pricing ) 上订阅 API

also, I couldn't find the endpoint you are trying to use ( /word_example ), looks like the right endpoint is /example .另外,我找不到您尝试使用的端点 ( /word_example ),看起来正确的端点是/example

You can always contact them at support@rapidapi.com您可以随时通过 support@rapidapi.com 与他们联系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RapidApi 安卓 - RapidApi Android 尝试将 amazon mturk SDK 实现到 android studio 项目时出错 - Error when trying to implement amazon mturk SDK into android studio project 尝试在 Android 工作室中实现 tensorflow lite model 时,我收到不兼容的数据类型错误 - When trying to implement tensorflow lite model in Android studio I am getting an incompatible data types error 尝试在Android Studio中实现getSharedPreferences时出现“无法解决方法”错误 - Getting “cannot resolve method” error when trying to implement getSharedPreferences in Android Studio 我正在尝试在 Android Studio 中实现蓝牙功能,需要一些帮助来解决连接问题 - I'm trying to implement Bluetooth functionality in Android Studio, need some help in connecting problem 任何人都可以告诉我我的 Android Studio Java 代码有什么问题...正在尝试实现底部导航栏 - Can Anyone Tell me whats the problem in my Android Studio Java Code... Trying to implement bottom Navigation Bar 尝试在Android Studio上使用Room - Trying to use Room on Android Studio 尝试在android中实现滑动视图时出现错误 - Errors when trying to implement Swipe Views in android 试图在android seekbar上实现max的动态增加 - trying to implement dynamic increase of max on android seekbar 试图在php中使用geofence在android中实现出勤 - trying to implement attendance in android using geofence with php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM