Question

I need to integrate login with different social media in iOS application. Currently I'm trying to display UserName and profilePic Image once the user login with his google + account. I have followed below youtube tutorial for the same: http://www.youtube.com/watch?v=M6ro0mib31M

From above tutorial I managed to do the login but I not getting any username and profilepic, both are returning null values.

Below are some of the important methods that I've implemented in my code

//Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    GPPSignIn *signIn=[GPPSignIn sharedInstance];
    signIn.clientID=@"123456789112.apps.googleusercontent.com";
    signIn.scopes=@[kGTLAuthScopePlusLogin];
    return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    NSLog(@"openUrl=%@", url);
    if([GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation])
        return YES;

      return NO;

}

//LoginViewController.h

@interface LoginViewController : UIViewController<GPPSignInDelegate>


- (IBAction)gPlusSignIn:(UIButton *)sender;


@property (weak, nonatomic) IBOutlet UIImageView *profileImage;


@property (weak, nonatomic) IBOutlet UILabel *displayName;

@end

//LoginViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    [GPPSignIn sharedInstance].delegate=self;
    [[GPPSignIn sharedInstance] trySilentAuthentication];

}

//This method is not getting called

-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
    [[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
    {
        self.profileImage.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:person.image.url]]];
        self.displayName.text=person.displayName;
        //Prints null in both
        NSLog(@"Name:%@, ProfilePic:%@",self.displayName.text,person.image.url);
    }];

}

- (IBAction)gPlusSignIn:(UIButton *)sender {
    [[GPPSignIn sharedInstance]authenticate];
}

Please suggest any possible solution for this.

Thanks in advance

Was it helpful?

Solution

I was able to resolve the issue by enabling the 'Google api' under the services tab at https://code.google.com/apis/console.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top