iOS Google 登录无法获取用户个人资料图片?(不是 Google plus 登录)

标签 ios objective-c google-plus-signin google-signin

我正在尝试在我的应用中使用 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/

相关文章:

ios - 捏合缩放 UIImage

iphone - 呈现一个屏幕大小一半的 View Controller

iphone - UIButton 触摸事件落入底层 View

objective-c - OS X 如何指定启动 View Controller

ios - iOS7 上错误的 UITableView 分隔符颜色

ios - 如何强制 MapView 覆盖 ViewController 上的所有空间?

javascript - 如何从 Google Sign-In Javascript SDK 获取访问 token ?

ios - 在 iOS 中的应用原生共享对话框和 google+ 登录

angular - 带有 Angular/Ionic : How do I find the redirect_uri? 的 Google OAuth 客户端

objective-c - 为 PDF 查看器自动调整 UIViews 的大小