使用Goodreads API for android

时间:2015-12-30 09:28:41

标签: android

我正在构建一个Android应用程序,需要用户对书籍的评论。在谷歌搜索后,我发现Goodreads API可以用于此目的。但问题是没有明确的java或android文档。

如何为我的应用使用 Goodreads API ?任何代码示例都可以解释。

2 个答案:

答案 0 :(得分:4)

Hello Guys,

               take the referral code form

[MarcBernstein /机器人-goodreads-API] https://github.com/MarcBernstein/android-goodreads-api

如果与您的Android工作室无法比较,在此之后执行以下代码更改。

在build.gradle中 -

    buildscript 
     {
    repositories {
    mavenCentral()
            }

    dependencies {
    classpath 'com.android.tools.build:gradle:2.1.3'
    classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.9.+'
    }
  }

apply plugin: 'com.android.application'

android {
 compileSdkVersion 19
 buildToolsVersion "19.1.0"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}

packagingOptions {
    exclude 'META-INF/maven/commons-io/commons-io/pom.xml'
    exclude 'META-INF/maven/commons-io/commons-io/pom.properties'
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}



buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), '        proguard-rules.txt'
    }
  }
}

 dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile project(':libraries:android-goodreads-api')
   compile 'com.squareup.picasso:picasso:2.+'
   compile 'com.squareup:otto:1.3.4'
   compile 'com.squareup.retrofit:retrofit:1.5.0'
   compile ('com.squareup.retrofit:converter-simplexml:1.5.0') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
  }
 compile 'org.json:json:20140107'
 compile 'org.apache.commons:commons-io:+'
 compile 'org.apache.commons:commons-lang3:+'
 compile 'com.google.guava:guava:16.+'
 compile 'com.google.code.gson:gson:+'
 compile 'oauth.signpost:signpost-core:+'
 compile 'oauth.signpost:signpost-commonshttp4:+'
 compile ('org.simpleframework:simple-xml:+') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
  }
 }

货物改变后,Api Gradle文件---

apply plugin: 'com.android.library'

android {
  compileSdkVersion 19
  buildToolsVersion '19.1.0'

 defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
 }

 compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
 }
 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.txt'
     }
  }
 }

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  compile 'com.squareup.picasso:picasso:2.+'
  compile 'com.squareup:otto:1.3.4'
  compile 'com.squareup.retrofit:retrofit:1.5.0'
  compile ('com.squareup.retrofit:converter-simplexml:1.5.0') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
  }
  compile 'org.json:json:20140107'
  compile 'org.apache.commons:commons-io:+'
  compile 'org.apache.commons:commons-lang3:+'
  compile 'com.google.guava:guava:16.+'
  compile 'com.google.code.gson:gson:+'
  compile 'oauth.signpost:signpost-core:+'
  compile 'oauth.signpost:signpost-commonshttp4:+'
  compile ('org.simpleframework:simple-xml:+') {
    exclude module: 'stax'
    exclude module: 'stax-api'
    exclude module: 'xpp3'
   }
 }

第3。更改Gradle文件的类路径。

<强> 4。配置数据

<string name="oauth_developer_key">your developer key</string>
<string name="oauth_developer_secret">your developer secret</string>
<string name="oauth_callback_url">com.goodreads://oauth_callback</string>

<强> 5。更改GoodreadsAPI库文件模块

private static final String API_URL =&#34; https://www.goodreads.com/&#34;;

private static final String AUTHORIZATION_WEBSITE_URL = "http://www.goodreads.com/oauth/authorize?mobile=1";
private static final String ACCESS_TOKEN_ENDPOINT_URL = "http://www.goodreads.com/oauth/access_token";
private static final String REQUEST_TOKEN_ENDPOINT_URL = "http://www.goodreads.com/oauth/request_token";

答案 1 :(得分:0)

Goodreads api是我见过的最糟糕的API之一。

您可以使用grapi library来简化它的工作。 剧透-我是作者。它是用现代科特林编写的。 您可以像这样使用它:

launch {
    val userId = grapi.getUserId()
    val shelves = grapi.getUserShelves(1, userId.id)
    val reviews = grapi.getReviewList(
            userId.id,
            "read",
            1, 2,
            sort = Sort.NUM_PAGES,
            order = Order.DESCENDING
    )
    val book = grapi.getBookByISBN("837054150X")
    val book2 = grapi.getBookByGRID("13588846")
    val res = grapi.getSearchResults("Wiedźmin")
    val user = grapi.getUser(userId.id)
    val allReviews = grapi.getAllReviews(userId.id)
}

如有任何问题或PR,请随时提出问题。