[英]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.