Getting 403 Forbidden Error When Connecting to RapidAPI in Android

Issue with API Integration

I’m working on integrating a vocabulary lookup service from RapidAPI into my Android app and running into authentication problems. When I make the API call, I keep getting a 403 Forbidden response.

public class WordLookup extends AppCompatActivity {
    private String selectedWord;
    private String apiHost = "word-service-api.p.rapidapi.com";
    private String myApiKey = "my-actual-api-key-here";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_word_lookup);
        
        selectedWord = getIntent().getStringExtra("word_to_search");
        fetchWordData();
    }
    
    private void fetchWordData() {
        OkHttpClient httpClient = new OkHttpClient();
        
        Request apiRequest = new Request.Builder()
                .url("https://word-service-api.p.rapidapi.com/definitions/?word=" + selectedWord)
                .get()
                .addHeader("X-RapidAPI-Host", apiHost)
                .addHeader("X-RapidAPI-Key", myApiKey)
                .build();
        
        httpClient.newCall(apiRequest).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("API_ERROR", "Request failed", e);
            }
            
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (!response.isSuccessful()) {
                    Log.e("API_ERROR", "Server returned error: " + response.code());
                    return;
                }
                
                String responseData = response.body().string();
                Log.d("API_SUCCESS", responseData);
            }
        });
    }
}

The error suggests authentication issues but I’m not sure if I’m missing some configuration step. I have my API key from RapidAPI dashboard but wondering if there are other required parameters I’m not including. Has anyone successfully integrated similar APIs and can point me in the right direction?

Had this exact problem last month with a different RapidAPI service. Turned out I was using the wrong endpoint URL. Double-check you’re using the exact URL from the RapidAPI docs for your subscription - sometimes the base URL’s slightly different from their examples. Also make sure your API key has the right permissions and hasn’t hit usage limits. I’d test with a simple curl request first to see if it’s Android-specific or just an auth issue. Oh, and verify your RapidAPI subscription’s actually active for that specific endpoint.

Check if your RapidAPI subscription’s still active - sometimes the dashboard shows your key even after it expires. Test with Postman first using the same headers. If it works there, it’s definitely an Android issue. Also, some APIs are picky about header order, so try putting X-RapidAPI-Key before X-RapidAPI-Host.

I’ve hit this 403 error tons of times with RapidAPI. Your code looks fine, but try URLEncoder.encode() on the word parameter - special characters mess things up. Also double-check your X-RapidAPI-Key header. Copy it straight from your dashboard and make sure there’s no extra spaces. Some APIs want a User-Agent or Content-Type header even for GET requests. Add some debug logging to see exactly what headers you’re sending vs what the docs say you need.