繁体   English   中英

如何获取accessToken(来自服务器的响应)

[英]How to get accessToken(response coming from the server)

您好停留在“ Retrofit2”上。 有人可以帮帮我,我怎么可能获得accessToken。 仅当用户登录时,才从服务器创建此“ accessToken”。 在此处输入图片说明

第1步:
从JSON生成对象。 您可以使用jsonToPojo android studio插件。

第2步:
来自onResponse的处理结果:

ApiCall apiService = ApiClient.getClient().create(ApiCall.class);
        Call<Api> callForLogin = apiService.getLoginResult("user_name","Password");
        callForDrawList.enqueue(new Callback<LoginResultObject>() {
            @Override
            public void onResponse(Call<LoginResultObject> call, Response<LoginResultObject> response) {
                String accessToken=response.body().getAccessToken());
            }

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

            }
        });

我认为这可能对您有帮助...谢谢

我假设您知道如何使用改造。 您需要的只是一个简单的请求,如下所示:

call.enqueue(new Callback<AuthenticationResponse>() {             @Override             public void onResponse(Call<AuthenticationResponse> call, Response<AuthenticationResponse> response) {                    if (response.code() == 200)                     mAuthenticateView.showPhoneNumberSentSuccessfully(response.body().getToken(), response.body().getExpiresIn());                 else                     mAuthenticateView.showMessage(response.message());             }             @Override             public void onFailure(Call<AuthenticationResponse> call, Throwable t) {     }         });

有关更多信息,请参见本教程: 将Retrofit 2.x用作REST客户端

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM