用google plus在parse.com上的ios上login
我已经通过我的iPhone应用程序通过Google+集成login,所有的作品都是完美的,但我想在Parse.comlogin到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. } }];
当我发送访问令牌,然后得到错误。
invalid session error. error code =101. 2.refreshToken
请任何人都可以帮助我login与谷歌加parse.com在ios中
在我上一个项目中,我做了这个,它工作正常。如果用户已经注册,那么它将login; 否则它启动注册过程。
- (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. } }]; }
这工作正常。 谢谢 ..
becomeInBackground方法需要您可以从ParseCloud应用程序获得的sessionToken。 经过一段时间找一个Parse + Google的例子,我创build了一个Github项目,你可以在这里find: https : //github.com/danielCarlosCE/parse-googlelogin
我从google获得一个accessToken
let gToken = user.authentication.accessToken
发送给我的ParseCloudfunction
PFCloud.callFunctionInBackground("accessGoogleUser", withParameters: ["accessToken":gToken])
获取sessionToken作为响应,并在成为方法中使用它
PFUser.becomeInBackground(sessionToken as! String)
ParseCloud项目,你可以在这里findhttps://github.com/danielCarlosCE/parsecloud-googlelogin
在main.js中,您需要使用Google的clientID信息更改此var
var clientsIds = ['iOSClientId','androidClientId'];
您传递给+becomeInBackground:block:
第一个参数(会话令牌)是parsing会话令牌,而不是Google+ / Facebook / Twitter。
此方法旨在与您自己的自定义stream程一起使用,您获得会话令牌的方式不同于提供用户名/密码,例如,通过CloudCode + SMS身份validation。
您可以使用如下所示的方式实施Google+login:
[PFUser logInWithUsernameInBackground:email password:@"yourSecretCommonPassword" block: ^(PFUser *user, NSError *error) { if ([error code] == kPFErrorObjectNotFound) { PFUser *currentUser = [PFUser currentUser]; currentUser.username = email; currentUser.password = @"yourSecretCommonPassword"; currentUser.email = email; currentUser[@"googleAuthToken"] = accessToken; currentUser[@"googleRefreshToken"] = refreshToken; [currentUser signUpInBackground]; } }];
- webView:didFailLoadWithError -1004:无法连接到服务器,同时在Phonegap ios连接谷歌加号
- Google plus API,用于在Facebook上发布信息
- Amazon Cognito iOS SDK V2使用Facebook和Google+提供者身份validation问题
- iOS Google+分享会提供空的预填文本
- 如何从Google(而不是从Google+)获取用户个人资料照片?
- 是否有可能直接发布谷歌加上没有额外的共享对话框在网上
- Google Plus使用UIWebViewloginiOS
- 是否有必要使用谷歌应用程序帐户来使用Google+域API?
- iOS的Google Plus API – 共享或login,而无需转到Safari