如何解决从Facebook Graph-API获取大型个人资料图片
我正在构建Kotlin应用程序,并且正在使用FirebaseAuth进行登录。我通过Firebase激活了Facebook登录,并且运行正常。我的问题是,创建的Firebase用户的photoUrl:(https://graph.facebook.com/<UserId>/picture
)指向其Facebook个人资料图片的一个很小的版本,而不是正常大小的。
我找到了以下解决方案:https://stackoverflow.com/a/52099896/13674106。这个答案的Google部分对我来说效果很好,但是在Facebook的情况下,我现在得到了默认的头像图片(分辨率合适)。我的代码如下:
fun handleSignInSucceeded(dataIntent: Intent?) {
val response = IdpResponse.fromResultIntent(dataIntent)
// For new created users,check if a photo is available from the auth provider
if (response?.isNewUser == true) {
// All users have a default FirebaseAuth provider data - we want to check which is the
// other one
currentUser.value?.providerData
?.find { it.providerId != FirebaseAuthProvider.PROVIDER_ID }?.apply {
val photoUrl = when (providerId) {
GoogleAuthProvider.PROVIDER_ID ->
photoUrl.toString().replace("s96-c","s400-c").toUri()
FacebookAuthProvider.PROVIDER_ID ->
photoUrl.toString().plus("?type=large").toUri()
else -> null
}
photoUrl?.let { updatePhotoUri(it,false) }
}
}
}
fun updatePhotoUri(photoUrl: Uri,uploadToStorage: Boolean = true): Task<Void>? {
val profileUpdates = UserProfileChangeRequest.Builder()
return if (uploadToStorage) ...
else updateProfile(profileUpdates.setPhotoUri(photoUrl).build())
}
private fun updateProfile(profileUpdates: UserProfileChangeRequest): Task<Void>? {
return currentUser.value?.updateProfile(profileUpdates)
?.addOnCompleteListener {
if (it.isSuccessful) {
Log.d(TAG,"User profile updated.")
_currentUser.value = firebaseAuth.currentUser
}
}
}
其中_currentUser
是私有MutableLiveData<FirebaseUser?>
的一部分,被称为LiveData<FirebaseUser?>
的公共user
遮盖,该公共<ImageView
android:id="@+id/image_profile_picture"
...
app:userPhotoSrc="@{profileViewModel.user}" />
绑定到片段上的我的ImageView:
userPhotoSrc
以下BindingAdapter
使用Glide
实现@BindingAdapter("userPhotoSrc")
fun ImageView.setUserPhotoSrc(user: FirebaseUser?) {
Glide.with(context)
.load(user?.photoUrl)
.circleCrop()
.fallback(R.drawable.ic_profile_black_24)
.into(this)
}
的地方:
user?.photoUrl
我签入了调试程序,此时的https://graph.facebook.com/<UserId>/picture?type=large
值为预期的height
。
我发现了这个线程:Retrieving Default Image All Url Profile Picture from Facebook Graph API,它显示了与我的线程类似的问题,但是根据那里的答案,我的代码现在应该可以正常工作了。我也尝试使用type
参数而不是cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.harbor.com"]
}
,就像这个答案中所说的:https://stackoverflow.com/a/50710161/13674106,但是我得到了相同的结果。
请帮助我解决它, 厄默尔
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。