我可以登录谷歌帐户,但无法获得用户访问令牌

时间:2013-06-14 06:10:14

标签: iphone google-plus access-token

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

1 个答案:

答案 0 :(得分: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);

  }
}];

} }