在 parse.com 上的 ios 中使用 google plus 登录 [英] Login with google plus in ios on parse.com

查看:20
本文介绍了在 parse.com 上的 ios 中使用 google plus 登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've integrated login via Google+ on my iphone app, all works perfect, but I want to login in ios app with Parse.com ,

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

already used this method but didn't work

[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.
  }
}]; 

当我在此发送访问令牌时出现错误.

when I send access token in this then got error.

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

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

Please any one can help me for login with google plus on parse.com in ios

推荐答案

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

In my last project, I did this and it's working fine .. If the user is already registered, then it will login; otherwise it initiates the signup process.

- (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.
        }
    }];

 }

一切正常.谢谢..

这篇关于在 parse.com 上的 ios 中使用 google plus 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆