[英]why finishedWithAuth: method didn't call?
I done google integration on my sample app, while i am trying to implement in my project the finishedWithAuth method didn't call. 我在示例应用程序上完成了google集成,而我试图在我的项目中实现未调用finishWithAuth方法。
0.its entering into google+ login screen. 0.its进入google +登录屏幕。
1.i done creating Oauth client key generation. 1.i完成了创建Oauth客户端密钥生成的工作。
2.Added gppsigninbutton. 2.添加了gppsigninbutton。
3.in appdelegate.m file 3.在appdelegate.m文件中
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if([FBSDKApplicationDelegate sharedInstance])
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
else
{
NSLog(@"entering");
return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
}
implemented 已实施
this is my code 这是我的代码
signIn.delegate = self;
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
//signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
// signIn.clientID=APIID;
signIn.homeServerClientID = kClientId;
// Uncomment one of these two statements for the scope you chose in the previous step
// signIn.scopes = @[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
// signIn.scopes = @[ @"profile" ]; // "profile" scope
signIn.scopes=[NSArray arrayWithObjects:kGTLAuthScopePlusLogin,kGTLAuthScopePlusMe, nil];
// Optional: declare signIn.actions, see "app activities"
[signIn trySilentAuthentication];
}
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(@"Received error %@ and auth object %@",error, auth);
if(error)
{
}
else
{
NSString *serverCode = [GPPSignIn sharedInstance].homeServerAuthorizationCode;
NSLog(@"this is server code%@",serverCode);
NSLog(@"user email%@", signIn.authentication.userEmail);
NSLog(@"user id%@",signIn.authentication.userID);
NSLog(@"auth token=%@",auth.accessToken);
NSString *str = [NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",auth.accessToken];
NSString* escapedUrl = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",escapedUrl]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:url usedEncoding:nil error:nil];
NSData *data = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"this is jsonvalues==%@",json);
if ( auth.userEmail)
{
[[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
{
// NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",person.image.url]];
// NSLog(@"%@",url);
// NSLog(@"Name:%@",person.displayName);
// NSLog(@"birthday:%@",person.birthday);
//
// NSLog(@"gender:%@",person.gender);
NSLog(@"peoplelist%@",person.displayName);
NSLog(@"peopleimae=%@",person);
// NSLog(@"people image%@",person.image);
// NSLog(@"people emailid%@",person.emails);
// imgurl = userData[@"picture"][@"data"][@"url"];
NSDictionary *dic=(NSDictionary *)person;
if(person.image)
{
NSLog(@"this is converted dictionary=%@",dic);
}
}];
// [self disconnect];
}
}
}
- (void)disconnect {
[[GPPSignIn sharedInstance] disconnect];
}
- (void)didDisconnectWithError:(NSError *)error {
if (error) {
NSLog(@"Received error %@", error);
} else {
// The user is signed out and disconnected.
// Clean up user data as specified by the Google+ terms.
}
}
It seems you are using both Facebook
and Google+
Sign In. 您似乎同时使用
Facebook
和Google+
登录。 So change your - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
to this: 因此,将您的
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
更改为此:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
NSString *stringURL = [ url absoluteString];
if([stringURL containsString:@"fb"])
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
else
{
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
}
Also code for loginWithGoogle should look like the following. loginWithGoogle的代码也应如下所示。 The problem is with your
signIn.scopes
. 问题出在您的
signIn.scopes
。
-(IBAction)loginWithGooglePressed:(id)sender
{
///
signIn = [GPPSignIn sharedInstance];
signIn.clientID = kClientId;
//signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
signIn.scopes= [NSArray arrayWithObjects:kGTLAuthScopePlusUserinfoEmail, nil];
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
[signIn trySilentAuthentication];
}
Works Fine for me: 对我有效:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.