2013-09-30 16 views
1

我需要在iOS應用程序中集成登錄與不同的社交媒體。目前,我試圖在用戶使用他的Google +帳戶登錄時顯示UserName和profilePic圖像。我已經按照下面的YouTube教程相同: http://www.youtube.com/watch?v=M6ro0mib31M用戶名和profilePic圖像通過google +在ios登錄後不顯示

從上面的教程我設法做登錄,但我沒有得到任何用戶名和profilepic,都返回空值。

下面是一些我在我的代碼已經實現

//Appdelegate.m

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

    GPPSignIn *signIn=[GPPSignIn sharedInstance]; 
    [email protected]"123456789112.apps.googleusercontent.com"; 
    [email protected][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]; 
} 

請爲此提出任何可能的解決方案。

在此先感謝

回答

相關問題