Home > Blockchain >  Getting 401 error while requasting GitHub API
Getting 401 error while requasting GitHub API

Time:08-14

I receive the access token in the first step And in the next step, when I try to use this access token to get user information, I get a 401 error. Api Service :

@Headers("Accept: application/json")
@GET("user")
fun getUserData(
    @Header("authorization") token: String
): Single<Response<UserResponse>>

my presenter :

    override fun callGetUserData(token: String) {
    Log.e("MainPresenter", "1")
    if (view.isNetworkAvailable()) {
        Log.e("MainPresenter", "2")
        view.showLoading()
        disposable = repository
            .getUserData(token)
            .applyIoScheduler()
            .subscribe { response ->
                Log.e("MainPresenter", "3")
                Log.e("MainPresenter", "${response.code()}")
                view.hideLoading()
                when (response.code()) {
                    in 200..202 ->
                        response.body()?.let { itBody ->
                            Log.e("LoginPresenter", "itBody : $itBody")
                            view.loadGetUserData(itBody)
                        }
                }

            }
    }
}

Mylogcat :

 E/MainPresenter: 1
 E/MainPresenter: 2
 E/MainPresenter: 3
 E/MainPresenter: 401

How can I fix this isuue? Thanks

CodePudding user response:

If you haven't already, ensure that your token is in the format of Bearer <token>

  • Related