0

我正在登录谷歌帐户,但无法获取登录用户访问令牌。在 GTMOAuth2Authentication.m 文件中,它仍然没有给我用户访问令牌。任何示例代码都会有很大帮助..

4

1 回答 1

1

在按钮单击时获取 google plus 登录数据..

-(IBAction)googleLogin:(id)sender{
  GPPSignIn *signIn = [GPPSignIn sharedInstance];
  [GPPSignInButton class];
  signIn.clientID = kClientID;
  signIn.delegate = self;
  signIn.shouldFetchGoogleUserEmail = TRUE;
  signIn.shouldFetchGoogleUserID=TRUE;
  signIn.scopes = [NSArray arrayWithObjects:
               @"https://www.googleapis.com/auth/plus.me",
               @"https://www.googleapis.com/auth/userinfo.profile",
               nil];

 [signIn authenticate];
 [signIn trySilentAuthentication];

}

和委托方法来获取信息

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error
   {
      NSLog(@"Received error %@ and auth object %@",error, auth);

      if (error) {
         // Do some error handling here.
      } else {
          NSLog(@"email:%@",auth.userEmail);
          NSLog(@"userData:%@",auth.userData);
           NSLog(@"user id is---%@",auth.userID);
           self.str=auth.accessToken;
           NSLog(@"my string value is---->%@",str);

///////////// for getting full profile inforamation///////////


        GTLServicePlus* plusService = [[[GTLServicePlus alloc] init] autorelease];
        plusService.retryEnabled = YES;
        [plusService setAuthorizer: auth];
         GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"];

          [plusService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error) {
         if (error) {
    GTMLoggerError(@"Error: %@", error);
  }
       else {
    // Get an array of people from GTLPlusPeopleFeed
         [person retain];
       NSString *description = [NSString stringWithFormat:@"%@\n%@\n%@\n%@\n%@\n%@", person.displayName,person.gender,person.image.url,person.relationshipStatus,person.name.familyName,person.name.givenName];
         NSLog(@"description:%@", description);

  }
}];

} }

于 2013-08-19T11:14:45.890 回答