GitHub API 返回 avatar_url 作为 null
GitHub API returning avatar_url as null
所以我的 Kotlin 应用程序使用 RetroFit 2。avatar_url、followers_url 等许多字段都 return 为空。
我使用的 api 是“https://api.github.com/users/{username}/received_events”
我的界面
interface RetroFitService {
@Headers("Authorization: {personal_auth_token}")
@GET("{username}/received_events")
fun getActivityList(): Call<MutableList<FeedPageModel>>}
我的 RetroFit 客户端对象
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!!
}
}
输出
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,
如您所见,多个字段 return 为 null,但在使用浏览器时相同的字段 return 带有数据。
请帮帮我:)
编辑
我的模型数据 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)
...和其他数据 classes...
检查 FeedPageModel 数据是否 所有变量 具有相同的变量在 kotlin 数据中具有相同的数据类型 class 与 api.
由于 某些变量类型转换抛出异常,变量给出 null
所以我的 Kotlin 应用程序使用 RetroFit 2。avatar_url、followers_url 等许多字段都 return 为空。 我使用的 api 是“https://api.github.com/users/{username}/received_events”
我的界面
interface RetroFitService {
@Headers("Authorization: {personal_auth_token}")
@GET("{username}/received_events")
fun getActivityList(): Call<MutableList<FeedPageModel>>}
我的 RetroFit 客户端对象
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!!
}
}
输出
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,
如您所见,多个字段 return 为 null,但在使用浏览器时相同的字段 return 带有数据。
请帮帮我:)
编辑 我的模型数据 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)
...和其他数据 classes...
检查 FeedPageModel 数据是否 所有变量 具有相同的变量在 kotlin 数据中具有相同的数据类型 class 与 api. 由于 某些变量类型转换抛出异常,变量给出 null