我正在尝试在我的应用中使用 google 登录,但遇到了问题。
(不是 google plus 登录,我使用的是 google 登录)
我关注了this link它有效。我得到 userID、user.authentication.idToken、user.profile.name 和 user.profile.email。
但是我找不到获取用户头像的方法。 上面的谷歌文档对此没有评论。
我在网上搜索了几个小时,但发现了我不想要的关于 google plus 登录的信息。
我在我的应用程序中实现了 Facebook 登录,他们提供了获取用户个人资料图片的 url。
Google 登录是否提供类似的服务?
这是我获取用户信息但没有图片的工作代码。
请帮忙
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
if (user) {
NSString *userId = user.userID; // For client-side use only!
NSString *token = user.authentication.idToken; // Safe to send to the server
NSString *name = user.profile.name;
NSString *email = user.profile.email;
...
}
最佳答案
你必须设置 [GIDSignIn sharedInstance].shouldFetchBasicProfile = YES;并使用下面的代码获取个人资料图片
if ([GIDSignIn sharedInstance].currentUser.profile.hasImage)
{
NSUInteger dimension = round(thumbSize.width * [[UIScreen mainScreen] scale]);
NSURL *imageURL = [user.profile imageURLWithDimension:dimension];
}
快速实现:
let dimension = round(thumbSize.width * UIScreen.mainScreen().scale);
let pic = user.profile.imageURLWithDimension(dimension)
关于iOS Google 登录无法获取用户个人资料图片?(不是 Google plus 登录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31707847/