Search code examples
androidkotlinretrofit2github-api

GitHub API returning avatar_url as null


So my Kotlin app uses RetroFit 2. Many fields like avatar_url, followers_url are returning null. The api i am using is "https://api.github.com/users/{username}/received_events"

My Interface

interface RetroFitService {
@Headers("Authorization: {personal_auth_token}")
@GET("{username}/received_events")
fun getActivityList(): Call<MutableList<FeedPageModel>>}

My RetroFit Client Object

object RetroFitClient {
private var retrofit: Retrofit? = null

fun getClient(baseUrl: String): Retrofit {
    if (retrofit == null) {
        retrofit = Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
    return retrofit!!
}

}

The OUTPUT

I/System.out: [FeedPageModel(id=15199828665, type=ForkEvent, actor=Actor(id=56252312, login=saikun0293, displayLogin=null, gravatarID=null, url=https://api.github.com/users/saikun0293, avatarURL=null), repo=Repo(id=229973079, name=GDGVIT/Resource-Hub, url=https://api.github.com/repos/GDGVIT/Resource-Hub), payload=Payload(forkee=Forkee(id=339402130, nodeID=null, name=Resource-Hub, fullName=null, private=false, owner=Owner(login=saikun0293, id=56252312, nodeID=null, avatarURL=null, gravatarID=null, url=https://api.github.com/users/saikun0293, htmlURL=null, followersURL=null, followingURL=null, gistsURL=null,

As you can see, various fields are returning null, but the same fields return with data while using a browser.

Kindly help me out please :)

EDIT My Model data class

data class FeedPageModel(
val id: String,
val type: String,
val actor: Actor,
val repo: Repo,
val payload: Payload,
val public: Boolean,
val createdAt: String,
val org: Actor? = null)

data class Actor(
val id: Long,
val login: String,
val displayLogin: String? = null,
val gravatarID: String,
val url: String,
val avatarURL: String)

data class Payload(
val forkee: Forkee? = null,
val action: String? = null,
val ref: String? = null,
val refType: String? = null,
val masterBranch: String? = null,
val description: String? = null,
val pusherType: String? = null,
val pushID: Long? = null,
val size: Long? = null,
val distinctSize: Long? = null,
val head: String? = null,
val before: String? = null,
val commits: List<Commit>? = null)

...and other data classes...


Solution

  • check if FeedPageModel data all variables have same variables has same data type in kotlin data class as api. Variables are giving null because of some variable type cast is throwing exception