API连接突然无法通过app工作



我正在制作一个实况足球应用程序,使用API-Sports他们的文档
它在两周前还可以工作。当我确定它起作用的时候,我也把我的git调回来了我使用Android Studio来构建应用程序,并使用OkHttp向API发出请求。

public class Testing extends AppCompatActivity {
private static String TAG = FixtureOverview.class.getName();
String host = "v3.football.api-sports.io";
String API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing);
Log.d(TAG, "onCreate called");
OkHttpClient client = new OkHttpClient();

Date dateTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String currentDate = formatter.format(dateTime);

Request request = new Request.Builder()
.url("https://v3.football.api-sports.io/fixtures?league=39&season=2021&date=" + currentDate)
.get()
.addHeader("x-rapidapi-host", host)
.addHeader("x-rapidapi-key", API_KEY)
.build();
System.out.println("request: " + request);
//Send API request
client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
Log.d(TAG, " onResponse of request called");
try (ResponseBody responseBody = response.body()) {
if (!response.isSuccessful()) {
Log.d("ChampionsTeamSelect onResponse", "unexpected code");
throw new IOException("Unexpected code " + response);
}
Headers responseHeaders = response.headers();
Log.d("ChampionsTeamSelect onResponse", "headers");
for (int i = 0, size = responseHeaders.size(); i < size; i++) {
System.out.println("response header: " + responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
try{
String jsonData = response.body().string();
System.out.println("jsonData: " + jsonData);
} catch (Exception e){
e.getMessage();
}
}
}

@Override
public void onFailure(Call request, IOException e) {
Log.d("EDMTERROR", "onfailure");
e.printStackTrace();
}
});
}
}

发送请求时使用以下代码

String jsonData = response.body().string();
System.out.println("jsonData: " + jsonData);

I/System.out: jsonData: {"get":"fixtures","parameters":{"league":"39","season":"2021","date":"2021-09-13"},"errors":{"token":"Error/Missing application key. Go to https://www.api-football.com/documentation-v3 to learn how to get your API application key."},"results":0,"paging":{"current":1,"total":1},"response":[]}

API-Sports有一个带有实时演示的仪表板,您可以在其中基本发送没有代码的请求,在这里它工作,使用相同的api-key。我还尝试更新api-key。

就像我说的,它过去是有效的。

我试着通过他们的聊天功能联系API-Sports,但一个多星期没有收到答复。

通过仪表板,我还可以看到他们的服务器正常运行。

代码中有什么错误吗,还有什么我可以尝试的吗?或者这是api方面的东西?在这种情况下,我必须尝试其他方式联系他们吗?

如果你的代码是工作之前,因为你提到的,那么似乎有一些问题从服务器端。您检查请求限制了吗?

您可以使用API- sports API的RapidAPI集成。如果它仍然不能工作,您可以随时写信给RapidAPI支持团队(support@rapidapi.com)。他们非常活跃,会解决你的问题。

最新更新