문제

I am developing an android app that makes use of Google Books. I found the API, registered an API KEY and want to use the library instead of parsing it myself like this. The code comes from sample project from Google. The project can be successfully compiled but it does not work. The "HELLO" is shown but "WORLD" is not.

Info: 1. The API key is correct. 2. Application name is not null. 3. Tried debugging in eclipse and also export to APK with keystore (registered with API key). Both failed to run the code.

Toast.makeText(this,"HELLO", 1).show();

// Set up Books client.
final Books books = new Books.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, null)
        .setApplicationName(APPLICATION_NAME)
        .setGoogleClientRequestInitializer(new BooksRequestInitializer(ClientCredentials.API_KEY))
        .build();
Toast.makeText(this, "WORLD", 1).show();

What is wrong with it?

By the way, is it necessary to export with keystore in order to run the above code and debug?

도움이 되었습니까?

해결책

Solution found:

  1. Use com.google.api.client.extensions.android.http.AndroidHttp.newCompatibleTransport instead of the Java one. Please refer to this.
  2. Use com.google.api.client.extensions.android.json.AndroidJsonFactory
  3. Be careful of android.os.NetworkOnMainThreadException. Read this.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top