1
votes

I have a problem restricting a Google Cloud Platform API key usage to an Android app: I have added its package name and certificate SHA-1 fingerprint (the debug one to get started) but it doesn't work.

My Cloud Platform API key panel

The error I get when calling any API is

403 Requests from this Android client application <empty> are blocked.

I'm calling the APIs by using a Cloud Endpoints generated client lib, and I've not been able to find any method that I can use at initialisation time to set the app credentials, nor does it do it by itself (as I can guess from the "<empty>" in the error). I can't find any useful info in any documentation as well, as far as I've red it seems like it should do it by itself.

This is my init code:

MyApi.Builder builder = new MyApi.Builder(new NetHttpTransport(), new AndroidJsonFactory(), null)
                .setApplicationName("<my package name>")
                .setRootUrl(<my root URL>)
                .setGoogleClientRequestInitializer(new MyApiRequestInitializer(<my API key>));

I've also tried what suggested in this answer but nothing changed.

Is there any passage I'm missing? How should it be done?

1
how did you configure your Cloud Endpoints? - Michael Meyer
Same problem here! - Juan Labrador
@MichaelMeyer , I've configured them using standard Cloud Endpoints Framework 2, use only with API Key. I've followed this example, method echoApiKey(Message message, @Named("n") @Nullable Integer n). - Cristina De Rito
@Ultimecia did you find an answer ?? - Ahmed D. Sherif
@AhmedD.Sherif unfortunately not yet... - Cristina De Rito

1 Answers

0
votes

I believe the problem appears only in emulators. I am getting the same error when running my app in an emulator. However, on real devices I do not seem to have the problem. Have you tested it on a real device?