2015-09-10 44 views
1

我想運行一個簡單的例子獲取Android產品詳細信息,我使用java示例作爲指南。 https://github.com/sphereio/sphere-hello-api/tree/master/javaCommercetools Sphereio SphereClient爲空

SphereClient sphere = SphereClient.create(
       new SphereClientConfig.Builder("xxxxxx", "xxxxxx", "xxxxxxxx", Locale.ENGLISH).build()); 

我得到錯誤:

io.sphere.client.SphereClientException: null: null 

我的build.gradle:

的Android { compileSdkVersion 22 buildToolsVersion '22 .0.1'

packagingOptions { 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/ASL2.0' 
} 

defaultConfig { 
    applicationId "com.spheretest" 
    minSdkVersion 15 
    targetSdkVersion 22 
    versionCode 1 
    versionName "1.0" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 

} 依賴關係編譯fileTree(包括:['* .jar'],dir:'libs') compile'c​​om.android.support:appcompat-v7:22.2.1' compile'io.sphere:sphere-java客戶端:0.60.0' }

是否有任何android示例我可以測試運行基本連接到球體?

堆棧跟蹤:

09-10 12:39:27.193 24611-24673/com.spheretest I/System.out﹕ 12:39:27.193 [Sphere-ClientCredentials-refresh-1] DEBUG sphere - [oauth] Refreshing access token. 
09-10 12:39:27.195 24611-24611/com.spheretest I/System.out﹕ 12:39:27.194 [main] DEBUG sphere - [cache] Refreshing category tree. 
09-10 12:39:27.206 24611-24611/com.spheretest I/System.out﹕ SphereClient== [email protected] 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ 12:39:27.896 [Sphere-ClientCredentials-refresh-1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ Non cached request 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ DefaultHttpRequest(chunked: false) 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ POST /oauth/token?grant_type=client_credentials&scope=manage_project%3Aorderjoy-85 HTTP/1.1 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ Host: auth-v0.sphere.io 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ Content-Type: application/x-www-form-urlencoded 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ Connection: keep-alive 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ Accept: */* 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ User-Agent: NING/1.0 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ [ 09-10 12:39:27.897 24611:24673 I/System.out ] 
    using Channel 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ [id: 0xb6a042f6, /192.168.1.3:38555] 
09-10 12:39:27.897 24611-24673/com.spheretest I/System.out﹕ [ 09-10 12:39:27.901 774: 3054 I/AccountManagerService ] 
    getTypesVisibleToCaller: isPermitted? true 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ 12:39:29.369 [New I/O worker #1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ [ 09-10 12:39:29.370 24611:24662 I/System.out ] 
    Request DefaultHttpRequest(chunked: false) 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ POST /oauth/token?grant_type=client_credentials&scope=manage_project%3Aorderjoy-85 HTTP/1.1 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Host: auth-v0.sphere.io 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Content-Type: application/x-www-form-urlencoded 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Connection: keep-alive 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Accept: */* 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ User-Agent: NING/1.0 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ [ 09-10 12:39:29.370 24611:24662 I/System.out ] 
    Response DefaultHttpResponse(chunked: true) 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ HTTP/1.1 401 Unauthorized 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Server: nginx 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Date: Thu, 10 Sep 2015 07:09:30 GMT 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Content-Type: application/json; charset=utf-8 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Transfer-Encoding: chunked 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Connection: keep-alive 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ WWW-Authenticate: Bearer realm="sphere", error="invalid_client", error_description="Please provide valid client credentials using HTTP Basic Authentication." 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Pragma: no-cache 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ Cache-Control: no-store 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ X-Correlation-ID: nginx-e04c33e0-0354-45fd-87eb-69a755c84a81 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ X-Served-By: app12.sphere.prod.commercetools.de 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ X-Served-Config: sphere-auth-ws-1.0 
09-10 12:39:29.370 24611-24662/com.spheretest I/System.out﹕ [ 09-10 12:39:29.378 24611:24662 I/System.out ] 
    12:39:29.378 [New I/O worker #1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - Sending authentication to https://auth-v0.sphere.io/oauth/token?grant_type=client_credentials&scope=manage_project%3Aorderjoy-85 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ 12:39:29.383 [New I/O worker #1] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ Non cached request 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ DefaultHttpRequest(chunked: false) 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ POST /oauth/token?grant_type=client_credentials&scope=manage_project%3Aorderjoy-85 HTTP/1.1 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ Host: auth-v0.sphere.io 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ Content-Type: application/x-www-form-urlencoded 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ Authorization: Basic SlI0STlQWTZmTU5HbG9JVWVsLWN6UEFPOkN1U2F4NmRCdHhfN0ZmWXNULUg2VUJvXzB6OXpEVGdR 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ Connection: keep-alive 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ Accept: */* 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ User-Agent: NING/1.0 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ [ 09-10 12:39:29.383 24611:24662 I/System.out ] 
    using Channel 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ [id: 0x04c9853c, /192.168.1.3:38556] 
09-10 12:39:29.383 24611-24662/com.spheretest I/System.out﹕ [ 09-10 12:39:29.479 24856:24868 W/com.worklight.common.Logger ] 
    com.worklight.common.Logger.setContext(Context) must be called to fully enable debug log capture. Currently, the 'capture' flag is set but the 'context' field is not. This warning will only be printed once. 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ 12:39:30.823 [New I/O worker #2] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider - 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ [ 09-10 12:39:30.824 24611:24663 I/System.out ] 
    Request DefaultHttpRequest(chunked: false) 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ POST /oauth/token?grant_type=client_credentials&scope=manage_project%3Aorderjoy-85 HTTP/1.1 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ Host: auth-v0.sphere.io 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ Content-Type: application/x-www-form-urlencoded 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ Authorization: Basic SlI0STlQWTZmTU5HbG9JVWVsLWN6UEFPOkN1U2F4NmRCdHhfN0ZmWXNULUg2VUJvXzB6OXpEVGdR 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ Connection: keep-alive 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ Accept: */* 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ User-Agent: NING/1.0 
09-10 12:39:30.824 24611-24663/com.spheretest I/System.out﹕ [ 09-10 12:39:30.824 24611:24663 I/System.out ] 
    Response DefaultHttpResponse(chunked: true) 
+0

你好,請你附上堆棧跟蹤?謝謝 – sebbulon

+0

@sebbulon stacktrace添加,客戶端ID和密碼是正確的,我可以符合 – mrYogi

回答

1

沒有爲commercetools平臺的SDK可以在所有的JVM語言( 「SPHERE JVM SDK」:https://github.com/sphereio/sphere-jvm-sdk)中使用,需要的Java 8語言特性因此在Android上不可用,因爲Android不是JVM。

您嘗試使用的「舊」SDK(不幸的是,它仍然用於Java Hello World示例中)在技術上與Android兼容,但我不推薦使用它,因爲它不再被維護(https://github.com/commercetools/sphere-play-sdk)。

截至今天,Android的客戶端,因此直接內置反對使用HTTP API一個Android內置的HTTP客戶端等
實際的答案:你可以找到與此谷歌眼鏡演示應用工作的Android樣品(GitHub上,麻省理工學院執照): https://github.com/sphereio/google-glass-demo

需要注意的一點是:SPHERE API的可用OAuth授權範圍目前還不足以構建完全原生的應用程序,包括直接針對commercetools(SPHERE)API簽出。您將不得不考慮是否本地執行結賬(即webview),或者(更好地)運行最小化服務器端API Shim,將公共應用的內容列入白名單,並執行OAuth並知道祕密。

對於像上面的Google Glass演示代碼這樣的原型/驗證概念,這不是問題。

+1

是不是很奇怪,有谷歌玻璃樣本,但仍然沒有任何關注基本的Android。正如你所說:SPHERE API目前功能不足以構建完全原生的應用程序。大多數商店目前都專注於移動.Still開發人員正在努力在本地移動實現Sphere。Sphere未來發展的重點是什麼? – mrYogi

+1

它有點不一致,這是正確的。但commerceools在路線圖上有它。您已在反饋門戶中創建了一個建議(http://support.sphere.io/forums/199144-general-feedback/suggestions/9698559-android-sdk-and-sample-needed),可以在此處跟蹤進度(會在這裏偏離主題)。 – nkuehn

1

與此同時,我們也爲移動設備提供了更好的支持。 例如,我們創建了一個Hello World爲Android,你可以作爲出發點使用移動應用程序: https://github.com/sphereio/commercetools-android-example

在不久的將來,我們將繼續擴展的移動平臺的支持。

+2

一個潛在的解決方案的鏈接總是值得歡迎的,但請[在鏈接附近添加上下文](http://meta.stackoverflow.com/a/8259/169503),以便您的同行用戶可以瞭解它是什麼以及爲什麼在那。如果目標網站無法訪問或永久離線,請始終引用重要鏈接中最相關的部分。考慮到_barely不僅僅是一個鏈接到外部網站_是一個可能的原因[爲什麼和如何刪除一些答案?](http://stackoverflow.com/help/deleted-answers)。 – Tunaki