如何使用Retrofit2获取令牌?

时间:2017-05-04 09:17:16

标签: android token retrofit2 yandex

来自令牌的响应格式

Yandeks.OAuth以JSON格式返回令牌及其生命时间:

200 OK
Content-type: application/json

{
  "access_token": "5fd980a5133b4887a8937fe07d3a0a60",
  "token_type": "bearer",
  "expires_in": 124234123534
}

接口OAuthServerIntf.class:

@FormUrlEncoded
@POST("authorize?response_type=token")
Call<OAuthTokenYandex> requestTokenForm1(
         @Field("client_id") String client_id
);

但是buider,它不是这样吗?错误json

@NonNull
    public static OAuthServerIntf yandexBuilder() {
        //Using Default HttpClient
        Retrofit retrofit = new Retrofit.Builder()
                .addConverterFactory(MoshiConverterFactory.create())
                .baseUrl("https://oauth.yandex.ru/")
                .build();
        OAuthServerIntf webServer = retrofit.create(OAuthServerIntf.class);
        return webServer;
    }

日志:

java.io.IOException: Use JsonReader.setLenient(true) to accept malformed JSON at path $

0 个答案:

没有答案