ios - 在 parse.com 的 ios 中使用 google plus 登录

标签 ios iphone authentication parse-platform google-plus

我已经在我的 iphone 应用程序上集成了通过 Google+ 登录,一切正常,但我想使用 Parse.com 登录 ios 应用程序,

已经用过这个方法但是没用

[PFUser becomeInBackground:@"session-token-here" block:^(PFUser *user, NSError *error) {
  if (error) {
    // The token could not be validated.
  } else {
    // The current user is now set to user.
  }
}]; 

当我在此发送访问 token 时出现错误。

 invalid session error. error code =101. 2.refreshToken

请任何人帮助我在 ios 中使用 parse.com 上的 google plus 登录

最佳答案

在我的上一个项目中,我这样做了并且工作正常..如果用户已经注册,那么它将登录;否则它会启动注册过程。

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth  error: (NSError *) error {
    NSLog(@"Received error %@ and auth object %@",error, auth);
    NSLog(@"user email %@  user id %@  user data %@, ",auth.userEmail,auth.userID, auth.userData);

    NSLog(@"email %@ ", [NSString stringWithFormat:@"Email: %@",[GPPSignIn sharedInstance].authentication.userEmail]);
    NSLog(@"Received error %@ and auth object %@",error, auth);

    NSString *userName = [[auth.userEmail componentsSeparatedByString:@"@"] objectAtIndex:0];
    PFUser *user = [PFUser user];
    user.username = userName;
    user.password = @"12345"; // It will use a common password for all google+ users.
    user.email = auth.userEmail;
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!error) {
             NSLog(@"Successful Registration");

            // Get the user's profile information 
             GTLServicePlus* plusService = [[GTLServicePlus alloc] init] ;
            plusService.retryEnabled = YES;

            // 2. Set a valid |GTMOAuth2Authentication| object as the authorizer.
            [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];

            GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"];

            [plusService executeQuery:query
                    completionHandler:^(GTLServiceTicket *ticket,
                                        GTLPlusPerson *person,
                                        NSError *error) {
                        if (error) {
                            GTMLoggerError(@"Error: %@", error);
                        } else {
                            // Retrieve the display name and "about me" text
                             NSLog(@"Name %@  Display name %@  Person about %@ person birthday %@"  ,person.name,person.displayName,person.aboutMe ,person.image);

                            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:person.image.url]];
                            PFFile *imageFile = [PFFile fileWithName:@"Profileimage.png" data:imageData];

                            PFUser *user = [PFUser currentUser];
                            // other fields can be set just like with PFObject
                            user[@"User_name"] = person.displayName;
                            user[@"user_image"] = imageFile;
                            [user saveInBackground];

                         }
                    }];

        } else {
             // If the user is already registered, then it'll login 
             NSLog(@"error %@",error);
            [PFUser logInWithUsernameInBackground:userName password:@"12345"
                                            block:^(PFUser *user, NSError *error) {
                                                NSLog(@"object id for me = %@", user.objectId);
                                                if (user) {
                                                     NSLog(@"user login success %@",user);
                                                }else{
                                                    NSLog(@"Error on Login %@",error);
                                                }
                                            }];
             // Show the errorString somewhere and let the user try again.
        }
    }];

 }

它工作正常。谢谢..

关于ios - 在 parse.com 的 ios 中使用 google plus 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24465232/

相关文章:

ios - 回到 Swift 2 中的 Facebook 问题

ios - 将字符串日期转换为 NSDate

http - 客户端应该如何将 facebook 访问 token 传递给服务器?

c# - 使用嵌套母版页检查身份验证和授权的最佳方法是什么

php - 如何使用 PHP 连接到 Linux?

ios - 应用程序在加载时崩溃并且根本没有调用 `didFinishLaunchingWithOptions`

ios - 通过 objective-c 模糊图像

ios - 从字符串中删除空格和多行?

iphone - 在 iPhone 上将音频文件与 NSData 正确组合为一个

iphone - Bundle ID 后缀与 info.plist 中的包标识符相同吗?