在parse.com上使用google plus登录ios

Hun*_*yWE 5 iphone login ios google-plus parse-platform

我在我的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.
  }
}]; 
Run Code Online (Sandbox Code Playgroud)

当我在此发送访问令牌然后得到错误.

 invalid session error. error code =101. 2.refreshToken
Run Code Online (Sandbox Code Playgroud)

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

Jog*_*Com 10

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

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

 }
Run Code Online (Sandbox Code Playgroud)

它工作正常.谢谢 ..

  • 感谢您的解决方案,但它只是从安全的角度来看我有一个静态密码.每个用户生成的不同哈希值(基于用户名和其他一些特定于应用程序的常量)可以提高安全性.由于parse.com SDK缺乏可扩展性,因此没有一个很好的解决方案. (4认同)