1

私のiPhoneアプリでは、を使用してGoogleサインインを使用してOauth2います。この指示に従い、正常にログインしています

- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController
      finishedWithAuth:(GTMOAuth2Authentication * )auth
                 error:(NSError * )error
{


if(!error)
    {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Success Authorizing with Google"

                                                         message:nil
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];
        [alert show];
    }

にhttps://www.googleapis.com/auth/userinfo.profileスコープを使用していますがGTMOAuth2Authentication、名前、年齢、電子メールなどのユーザーの基本情報を取得したいと考えています。

では、どうすればすべての詳細を取得できますか??
私はたくさん検索しましたが、何も見つかりませんでした。

おそらくiOSでOAuth2ユーザー情報を取得する方法の重複した質問? 、しかしそれも役に立ちません。

助けてください

4

2 に答える 2

5

デフォルトでは、GTMOAuth2ViewControllerTouch viewController はユーザーのメールをフェッチしますが、ユーザーの残りのプロファイルはフェッチしません。
サインインする前にこのプロパティを設定することで、Google のサーバーから完全なプロファイルをリクエストできます。

GTMOAuth2ViewControllerTouch *viewController; viewController.signIn.shouldFetchGoogleUserProfile = YES;

プロファイルは、次のようにサインインした後に使用できます。

   NSDictionary *profile = viewController.signIn.userProfile;

他の情報を取得するには、scope文字列を変更して再度フェッチを開始する必要があります。

ここにいくつかのスコープ URL があります

@"https://www.googleapis.com/auth/plus.me"

@"https://www.googleapis.com/auth/userinfo.email"

@"https://www.googleapis.com/auth/tasks"

于 2013-08-01T10:19:54.187 に答える
0

このコードを使用して解決しました

 NSURL *url = [NSURL URLWithString:@"https://www.googleapis.com/plus/v1/people/me/activities/public"];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
            [self.auth authorizeRequest:request
                      completionHandler:^(NSError *error) {
                          NSString *output = nil;
                          if (error) {
                              output = [error description];
                          } else {
                              // Synchronous fetches like this are a really bad idea in Cocoa applications
                              //
                              // For a very easy async alternative, we could use GTMHTTPFetcher
                              NSURLResponse *response = nil;
                              NSData *data = [NSURLConnection sendSynchronousRequest:request
                                                                   returningResponse:&response
                                                                               error:&error];
                              if (data) {
                                  // API fetch succeeded
                                  output = [[NSString alloc] initWithData:data
                                                                 encoding:NSUTF8StringEncoding] ;

                                  NSError* error;
                                  NSDictionary* json = [NSJSONSerialization
                                                        JSONObjectWithData:data

                                                        options:kNilOptions
                                                        error:&error];



                                  NSArray *array=[json objectForKey:@"items"];
                                  if (array.count>0) {
                                      NSDictionary *dicts=[array objectAtIndex:0];

                                      //  NSLog(@"actor:%@",[dicts objectForKey:@"actor"]);
                                      //[self updateUI:[dicts objectForKey:@"actor"]];
                                      // [dictUserInfo setObject:[[[dicts objectForKey:@"actor"] objectForKey:@"image"]objectForKey:@"url"] forKey:@"imageUrl"];


                                      if([delegate respondsToSelector:@selector(userPicChanged:)])
                                      {
                                          //send the delegate function with the amount entered by the user
                                          [delegate userPicChanged:[[[dicts objectForKey:@"actor"] objectForKey:@"image"]objectForKey:@"url"]];
                                      }



                                  }


                              } else {
                                  // fetch failed
                                  output = [error description];
                              }
                          }
                      }];
于 2013-08-05T11:33:02.830 に答える