1

I am trying to run a simple sample of getting product details in android. I am using java sample as guide.

https://github.com/sphereio/sphere-hello-api/tree/master/java

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

I am getting this error:

io.sphere.client.SphereClientException: null: null

My 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'
    }
}

} dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:22.2.1' compile 'io.sphere:sphere-java-client:0.60.0' }

Is there is any android sample I can test run for basic connection to Sphere?

Stacktrace:

    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== io.sphere.client.shop.SphereClient@76338d
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)
Jasperan
  • 2,154
  • 1
  • 16
  • 40
mrYogi
  • 992
  • 2
  • 9
  • 29

2 Answers2

1

there is an SDK for the commercetools platform that can be used in all JVM languages ("SPHERE JVM SDK": https://github.com/sphereio/sphere-jvm-sdk), but that requires Java 8 language features and is therefore not usable on Android because, well, Android is not a JVM.

The "old" SDK you're trying (and which is unfortunately still used in the Java Hello World example) is technically Android-compatible but I would not recommend using it as it's not maintained any more (https://github.com/commercetools/sphere-play-sdk).

As of today, Android clients are therefore built directly against the HTTP API using an Android built-in HTTP client etc.
The actual answer: You can find a working Android Sample with this Google Glass demo app (GitHub, MIT License): https://github.com/sphereio/google-glass-demo.

One caveat: the available OAuth authorization scopes of the SPHERE API are currently not powerful enough to build a fully native app including checkout directly against the commercetools (SPHERE) API. You will have to consider to either not doing checkout natively (i.e. webview), or (better) running a minimal server-side API shim that whitelists content for the public app and does the OAuth and knows secrets.

For a prototype / proof of concept like the Google Glass demo code above that isn't an issue nevertheless.

nkuehn
  • 138
  • 10
  • 1
    is it not weird that there is sample of google glass but still there is not any focus on basic android. as you said : SPHERE API are currently not powerful enough to build a fully native app. Most stores are currently focussing mobile .Still developers struggling in implementing Sphere on mobile natively.What is focus of future development in Sphere? – mrYogi Sep 10 '15 at 12:34
  • 1
    It is somewhat inconsistent, that's correct. But commerceools has it on the roadmap. You already created a suggestion in the feedback portal ( http://support.sphere.io/forums/199144-general-feedback/suggestions/9698559-android-sdk-and-sample-needed ), progress can be tracked there (would be offtopic here). – nkuehn Sep 11 '15 at 07:15
1

In the mean time, we've worked on a better support for mobile. For example, we created a Hello World for Android, that you can use as starting point for your mobile application: https://github.com/sphereio/commercetools-android-example

In the near future, we will continue to extend the support of mobile platforms.

Yann Simon
  • 458
  • 3
  • 11
  • 2
    A link to a potential solution is always welcome, but please [add context around the link](http://meta.stackoverflow.com/a/8259/169503) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being _barely more than a link to an external site_ is a possible reason as to [Why and how are some answers deleted?](http://stackoverflow.com/help/deleted-answers). – Tunaki Feb 24 '16 at 11:09