I'm trying to make google sign-in work in my app but have an issue.
(NOT a google plus sign-in, I'm using google sign-in)
I followed this link and it works. I get userID, user.authentication.idToken, user.profile.name, and user.profile.email.
But I can't find out the way how I get the user profile picture. Above google docs have no comment on that.
I searched web for hours but found about google plus sign-in only which I don't want.
I implemented Facebook sign-in in my app and they provide the url that fetches user profile picture.
Does google sign-in serve something like that?
This is my working code fetching user info but no picture.
Please help
- (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;
...
}
you have to set [GIDSignIn sharedInstance].shouldFetchBasicProfile = YES; and the use below code for get profile pic
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)
Swift 3
let dimension = round(imageSize.width * UIScreen.main.scale)
let pic = userInfo.profile.imageURL(withDimension: dimension)
imageSize.width is required width of image.
let dimension = round(100 * UIScreen.main.scale)
let pic = userInfo.profile.imageURL(withDimension: dimension)
Thanks Amit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With