我需要在iOS应用程序中将登录信息与其他社交媒体集成在一起。目前,我正在尝试在用户使用其Google +帐户登录后显示UserName和profilePic图像。我遵循以下youtube教程进行相同操作:http : //www.youtube.com/watch?v=M6ro0mib31M
通过上面的教程,我设法进行了登录,但是没有得到任何用户名和profilepic,它们都返回空值。
以下是我在代码中实现的一些重要方法
//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];
}
请提出任何可能的解决方案。
提前致谢
通过在https://code.google.com/apis/console的“服务”标签下启用“ Google api”,我能够解决此问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句