无法在Google +集成上获取用户名?

基肖尔·库马尔(Kishore Kumar)

这是我的代码

   - (void)viewDidLoad {
        [super viewDidLoad];

        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.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];
        signIn.shouldFetchGoogleUserEmail=YES;
        // Optional: declare signIn.actions, see "app activities"
        signIn.delegate = self;

        [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(@"%@", signIn.authentication.userEmail);
            GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
            plusService.retryEnabled = YES;
            [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
    //        [plusService setAuthorizer:signIn.authentication];
            GTLQueryPlus *query =
            [GTLQueryPlus queryForPeopleListWithUserId:@"me"
                                            collection:kGTLPlusCollectionVisible];
            [plusService executeQuery:query
                    completionHandler:^(GTLServiceTicket *ticket,
                                        GTLPlusPerson *peopleFeed,
                                        NSError *error) {
                        if (error) {
                            GTMLoggerError(@"Error: %@", error);
                        } else {
                            // Get an array of people from GTLPlusPeopleFeed
    //                        NSArray* peopleList = peopleFeed.image;
    //                        NSLog(@"peoplelist%@",peopleFeed.image);
                            NSLog(@"peoplelist%@",peopleFeed);
                            NSLog(@"name=%@",peopleFeed.name);//crashed here



                        }
                    }];
        }
    }

我的代码输出:

2015-10-30 10:27:52.335 Gintegration[652:16537] this is server code4/0m16vNMNOQV3PbjetJiBeIubCwb3safO0V5F14Q5t3o
2015-10-30 10:27:52.335 Gintegration[652:16537] [email protected]
2015-10-30 10:27:52.928 Gintegration[652:16537] peoplelistGTLPlusPeopleFeed 0x78e783c0: {title:"Google+ List of Visible People" etag:""MrhFVuKLF7zHXL6gE2l7cEdzuiA/EyyvLoAPddEjQ_gTun2BNflcftA"" nextPageToken:"CGQQjN3vuIsq" totalItems:108 kind:"plus#peopleFeed" items:[100]}
2015-10-30 10:27:52.928 Gintegration[652:16537] -[GTLPlusPeopleFeed name]: unrecognized selector sent to instance 0x78e783c0
2015-10-30 10:27:52.989 Gintegration[652:16537] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GTLPlusPeopleFeed name]: unrecognized selector sent to instance 0x78e783c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x02b8aa94 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0264be02 objc_exception_throw + 50
    2   CoreFoundation                      0x02b93de3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x02ad1e3d ___forwarding___ + 1037
    4   CoreFoundation                      0x02ad1a0e _CF_forwarding_prep_0 + 14
    5   Gintegration                        0x0009322b __42-[ViewControllerS finishedWithAuth:error:]_block_invoke + 283
    6   Gintegration                        0x0009e802 -[GTLService handleParsedObjectForFetcher:] + 1646
    7   libobjc.A.dylib                     0x02660059 -[NSObject performSelector:withObject:] + 70
    8   Foundation                          0x009216e8 __NSThreadPerformPerform + 323
    9   CoreFoundation                      0x02aa4e7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    10  CoreFoundation                      0x02a9ab0b __CFRunLoopDoSources0 + 523
    11  CoreFoundation                      0x02a99f28 __CFRunLoopRun + 1032
    12  CoreFoundation                      0x02a99866 CFRunLoopRunSpecific + 470
    13  CoreFoundation                      0x02a9967b CFRunLoopRunInMode + 123
    14  GraphicsServices                    0x04380664 GSEventRunModal + 192
    15  GraphicsServices                    0x043804a1 GSEventRun + 104
    16  UIKit                               0x0122acc1 UIApplicationMain + 160
    17  Gintegration                        0x0009356a main + 138
    18  libdyld.dylib                       0x03c88a21 start + 1
    19  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

如果我的代码有任何错误,请指出。

我正在获取电子邮件ID,但是在尝试获取用户个人资料信息时却出现错误。请任何人帮助我克服这个问题。

安布·卡尔提克(Anbu.Karthik)

{title:“ Google+可见人员列表” etag:““ MrhFVuKLF7zHXL6gE2l7cEdzuiA / EyyvLoAPddEjQ_gTun2BNflcftA”“ nextPageToken:” CGQQjN3vuIsq“ totalItems:108种类:” plus#peopleFeed“

上面的Dictionary包含Name键不可用,这就是它崩溃的原因。

尝试这个

- (void)viewDidLoad {
    [super viewDidLoad];

      GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.clientID=@GOOGLE_PLUS_Login_ID;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.scopes = @[ @"profile" ];

signIn.delegate = self;

if (![signIn trySilentAuthentication])
    [signIn authenticate];
}

-(void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
 if (error) {
    // Do some error handling here.
} else {
//         NSLog(@"Received error %@", auth.userEmail);
//         NSLog(@"Received error %@", auth.accessToken);

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


                }

 }
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章