2015-10-30 80 views
0

enter image description herewhyWithAuth:方法沒有調用?

我完成了谷歌在我的示例應用程序集成,而我試圖在我的項目中落實finishedWithAuth方法沒有調用。

0.its進入google +登錄屏幕。

1.i完成創建Oauth客戶端密鑰生成。

2.增加了gppsigninbutton。

3.in 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]; 
    } 


} 

實施

  • URL也加入的.plist。
  • 這是我的代碼

     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. 
        } 
    } 
    

    enter image description here

    +0

    添加一些代碼.... –

    +0

    其中的代碼區你想老兄...... @ Anbu.Karthik –

    +0

    @ Anbu.Karthik任何兄弟問題與clientID –

    回答

    0

    似乎你同時使用FacebookGoogle+登錄。因此,改變你的- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation這樣的:對於loginWithGoogle

    - (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]; 
    
        } 
    } 
    

    而且代碼應如下所示。問題出在您的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

    +0

    好的,我試着用你的代碼... –

    +0

    @KishoreKumar你的問題解決了嗎? – Rumin

    +0

    no bro .......... –

    相關問題