Uber Refresh Authenticator崩溃

时间:2016-07-19 11:07:22

标签: java oauth-2.0 uber-api

我的应用在执行uber webSetup后收到accessTokenrefreshTokenexpiryTimeInMillis。这些我通过StoredCredential存储在文件中。每当我必须创建会话时,我都会通过读取Credential中存储的值来创建StoredCredential,如下所示。

private Credential createCredential(){
    Credential.Builder builder = new Credential.Builder(new Credential.AccessMethod() {
        @Override
        public void intercept(HttpRequest request, String accessToken) throws IOException {
            /**
             * Do nothing
             */
        }

        @Override
        public String getAccessTokenFromRequest(HttpRequest request) {
            /**
             * Do nothing
             */
            return null;
        }
    });
    builder.setTransport(new MockHttpTransport());
    builder.setJsonFactory(new MockJsonFactory());
    builder.setClientAuthentication(new BasicAuthentication("user","pass"));

    String query = "";
    try {
        query = URLEncoder.encode("mock", "utf-8");
    } catch (UnsupportedEncodingException e) {
        Log.v(TAG,"UnsupportedEncodingException ");
    }
    String url = "http://mockaddress.com/search?q=" + query;
    builder.setTokenServerEncodedUrl(url);
    return builder.build();
}


public void setCredentialsFromWebSetup(String accessToken, String refreshToken, long expire_at){
    credential = createCredential();
    credential.setAccessToken(accessToken);
    credential.setRefreshToken(refreshToken);
    credential.setExpirationTimeMilliseconds(expire_at);
}

我的问题是:

  1. accessToken已过期,我不知道如何使用refreshToken续订。

  2. 我认为当我传递accessTokenRefreshTokenExpiryTime,查看uber-java-sdk代码时,Uber SDK会处理更新accessToken的问题。

  3. 在使用accessToken续订新refreshToken后,我将如何收到通知。

  4. 我没有为优步登录客户端。我的设备上没有Uber应用程序。我正在使用uber-rides-java SDK构建应用程序,该应用程序使用超级API预订/取消/查看乘车详情。

    我看到这次崩溃并没有太多与我的问题有关的帮助。

      

    E / AndroidRuntime(20417):java.lang.IllegalArgumentException:找不到JSON输入   E / AndroidRuntime(20417):在com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:92)   E / AndroidRuntime(20417):at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:49)   E / AndroidRuntime(20417):在com.google.api.client.json.JsonParser.startParsing(JsonParser.java:222)   E / AndroidRuntime(20417):在com.google.api.client.json.JsonParser.parse(JsonParser.java:379)   E / AndroidRuntime(20417):在com.google.api.client.json.JsonParser.parse(JsonParser.java:354)   E / AndroidRuntime(20417):在com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)   E / AndroidRuntime(20417):在com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)   E / AndroidRuntime(20417):在com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)   E / AndroidRuntime(20417):在com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)   E / AndroidRuntime(20417):at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570)   E / AndroidRuntime(20417):at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)   E / AndroidRuntime(20417):at com.uber.sdk.rides.auth.CredentialsAuthenticator.refreshAndSign(CredentialsAuthenticator.java:97)   E / AndroidRuntime(20417):at com.uber.sdk.rides.auth.CredentialsAuthenticator.reauth(CredentialsAuthenticator.java:77)   E / AndroidRuntime(20417):at com.uber.sdk.rides.auth.CredentialsAuthenticator.refresh(CredentialsAuthenticator.java:58)   E / AndroidRuntime(20417):at com.uber.sdk.rides.client.internal.RefreshAuthenticator.authenticate(RefreshAuthenticator.java:46)   E / AndroidRuntime(20417):at okhttp3.internal.http.HttpEngine.followUpRequest(HttpEngine.java:893)   E / AndroidRuntime(20417):在okhttp3.RealCall.getResponse(RealCall.java:276)   E / AndroidRuntime(20417):在okhttp3.RealCall $ ApplicationInterceptorChain.proceed(RealCall.java:198)   E / AndroidRuntime(20417):在okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:142)   E / AndroidRuntime(20417):在okhttp3.RealCall $ ApplicationInterceptorChain.proceed(RealCall.java:187)   E / AndroidRuntime(20417):at com.uber.sdk.rides.client.internal.ApiInterceptor.intercept(ApiInterceptor.java:57)   E / AndroidRuntime(20417):在okhttp3.RealCall $ ApplicationInterceptorChain.proceed(RealCall.java:187)   E / AndroidRuntime(20417):在okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)   E / AndroidRuntime(20417):在okhttp3.RealCall.access $ 100(RealCall.java:30)   E / AndroidRuntime(20417):在okhttp3.RealCall $ AsyncCall.execute(RealCall.java:127)   E / AndroidRuntime(20417):在okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)   E / AndroidRuntime(20417):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)   E / AndroidRuntime(20417):at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)   E / AndroidRuntime(20417):at java.lang.Thread.run(Thread.java:818)   W / ActivityManager(1063):强制完成活动com.iamplus.uberapp / .MainActivity

1 个答案:

答案 0 :(得分:0)

看起来你正在Android上使用Uber Java SDK。请使用不使用Google OAuth Credential类的Uber Android SDK,并且实施的重量要轻得多。