2017-08-08 65 views
2

我想实现oAuth 1.0使用翻新获取请求,但无法获得响应。邮差的oAuth 1.0获取请求翻新android

enter image description here

响应:

{ 
    "1": { 
     "entity_id": "1", 
     "parent_id": "0", 
     "position": "0", 
     "level": "0", 
     "name": "Root Catalog" 
    }, 
    "2": { 
     "entity_id": "2", 
     "parent_id": "1", 
     "position": "1", 
     "level": "1", 
     "name": "Default Category", 
     "is_active": "1" 
    } 
} 

我的界面:

@GET("/api/rest/categories/?") 
    @Headers({ "Content-Type: application/json"}) 
    Call<ResponseBody> getProduct(@Field("oauth_consumer_key") String grantType, 
            @Field("oauth_token") String username, 
            @Field("oauth_signature_method") String sig, 
            @Field("oauth_timestamp") String timS, 
            @Field("oauth_nonce") String nonc, 
            @Field("oauth_version") String vers, 
            @Header("Authorization") String authorization); 

方法调用:

私人无效callService(){

byte[] credentials = "CONSUMER_SECRETE:TOKEN_SECRETE".getBytes(); 
String basicAuth = "Basic " + Base64.getEncoder().encodeToString(credentials); 

UserClient apiService = ApiClient.getClient().create(UserClient.class); 
Call<ResponseBody> call = apiService.getProduct("CONSUMER_KEY","TOKEN_KEY","HMAC-SHA1","1502218838","RuH2FG","1.0",basicAuth); 
call.enqueue(new Callback<ResponseBody>() { 
    @Override 
    public void onResponse(Call<ResponseBody>call, Response<ResponseBody> response) { 
     if (response.isSuccessful()){ 
      if (response.isSuccessful()){ 

      }else{ 
       Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_LONG).show(); 
      } 
     }else{ 
      //First Option of error handling.. 
      switch(response.code()){ 
       case 404: 
        Toast.makeText(getApplicationContext(),R.string.server_error404, Toast.LENGTH_SHORT).show(); 
        break; 
       case 500: 
        Toast.makeText(getApplicationContext(),R.string.server_error500, Toast.LENGTH_SHORT).show(); 
        break; 
       default: 
        Toast.makeText(getApplicationContext(),R.string.server_errorUnknow, Toast.LENGTH_SHORT).show(); 
      } 
     } 


    } 
    @Override 
    public void onFailure(Call<ResponseBody>call, Throwable t) { 

     Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_LONG).show(); 
    } 
}); 

}

有什么我也试过: Android OAuth Retrofit Access Token Request

,并尝试其他类型的,但他们都没有工作。

任何人都可以帮我解决这个问题吗?我想通过改造来实现这一点。

+0

你得到解决? –

+0

请添加您的解决方案,我坚持认证1.0 api @SubinBabu –

回答

0

请尝试此解决方案,

下面的代码添加到您的API接口调用标题

@Headers({ 
      "Content-Type: application/json;charset=utf-8", 
      "Accept: application/json;charset=utf-8", 
      "Cache-Control: max-age=640000", 
    }) 
+0

是否适合您@Ameer Sabith –