android - GitHub API 将 avatar_url 返回为 null
问题描述
所以我的 Kotlin 应用程序使用 RetroFit 2。很多字段,如 avatar_url、followers_url 都返回 null。我使用的 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,
如您所见,各种字段都返回 null,但在使用浏览器时,相同的字段会返回数据。
请帮帮我:)
编辑我的模型数据类
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)
...和其他数据类...
解决方案
检查 FeedPageModel 数据是否所有变量都具有相同的变量在 kotlin 数据类中具有与 api 相同的数据类型。由于某些变量类型转换抛出异常,变量给出 null
推荐阅读
- amazon-web-services - 当用户更改密码、注销、刷新令牌时在 AWS Cognito 中捕获日志
- python - 根据另外两个中的值创建一个新列
- sql - 如何将 sqlplus 参数从 shell 脚本传递到 sql 文件
- javascript - 是否可以仅使用服务器端 Javascript 来验证 google recapctha 响应
- python - Python: Compare Lists
- javascript - 为什么我们需要在 setTimeout() 中将时间设置为 i*time 而不仅仅是时间
- python - 在 Hugging Face BertForSequenceClassification 中有 6 个标签而不是 2 个标签
- couchbase - Couchbase 分析:无结果和 couchbase 内部服务器错误,索引具有 UNIXTIME 毫秒时间戳
- java - JBOSS EAP 7.1 部署错误 - 操作数堆栈上的类型错误
- oop - 使用通用 ViewModel 设计应用程序