本文介绍了在parse.com上使用google plus登录ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在我的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上使用google.com登录google plus / p>
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上使用google plus登录ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!