2014-10-04 96 views
5

我正在使用Parse,用户可以在哪里使用Facebook,Twitter和Google+登录。截至目前,只有Facebook和Twitter功能齐全。解析Google plus登录

我设法以下列方式使用Facebook和Twitter登录:

private void onLoginButtonClicked() { 
     LoginActivity.this.progressDialog = ProgressDialog.show(
       LoginActivity.this, "", "Logging in...", true); 
     List<String> permissions = Arrays.asList("public_profile", "user_about_me", 
       "user_relationships", "user_birthday", "user_location"); 
     ParseFacebookUtils.logIn(permissions, this, new LogInCallback() { 
      @Override 
      public void done(ParseUser user, ParseException err) { 
       LoginActivity.this.progressDialog.dismiss(); 
       if (user == null) { 
        Log.d(IntegratingFacebookTutorialApplication.TAG, 
          "Uh oh. The user cancelled the Facebook login."); 
       } else if (user.isNew()) { 
        Log.d(IntegratingFacebookTutorialApplication.TAG, 
          "User signed up and logged in through Facebook!"); 
        showUserDetailsActivity(); 

       } else { 
        Log.d(IntegratingFacebookTutorialApplication.TAG, 
          "User logged in through Facebook!"); 
       moodpage();    

       } 
      } 
     }); 
    } 

    private void onTwitterButtonClicked() { 
     ParseTwitterUtils.logIn(this, new LogInCallback() { 
       @Override 
       public void done(ParseUser user, ParseException err) { 
       if (user == null) { 
        Log.d("MyApp", "Uh oh. The user cancelled the Twitter login."); 
       } else if (user.isNew()) { 
        Log.d("MyApp", "User signed up and logged in through Twitter!"); 
        showUserDetailsActivity();   
        } else { 
        Log.d("MyApp", "User logged in through Twitter!"); 
        moodpage();    } 
       } 

      }); 
    } 

我试图找出通过解析使用Google+实现这一目标。有人建议我查看Parse Rest API,但是,我不熟悉它,需要更多指导。

任何澄清将不胜感激。

+0

[这里](https://parse.com/docs/rest)是Parse API文档,[这里](https://parse.com/docs/android_guide)是Android的指南。你有没有尝试谷歌至少? – 2014-10-04 21:12:20

+0

@ user3907211还有其他一些促进google +登录的java库。你感兴趣吗? – Alboz 2014-10-04 21:16:37

+0

我会感兴趣。有很多方法可以做到,但我想在解析中创建一个关系,解析存储用户登录google +信息。 – John 2014-10-04 21:21:17

回答

0

按本:

http://blog.parse.com/announcements/adding-third-party-authentication-to-your-web-app/

这:

https://parse.com/tutorials/adding-third-party-authentication-to-your-web-app

而且我对他们的了解

你只需要使用一些算法来生成密码在你的应用程序或你的云/后端,af之三成功登录在使用Google+/Github上/无论

一个simeple执行(但它不是固定有它在你的应用程序):

// given Google Plus login (Using their Api) i.e. no Parse yet at this point 
int id = 12345; // assume that this is google+ id (After successfully logging in) 

ParseUser user = new ParseUser(); 
user.setUsername("google-plus-" + String.valueOf(id)); 
user.setPassword(hashMyPassword(id)); // Create password based on the id 
user.setEmail("[email protected]"); 

user.signUpInBackground(new SignUpCallback() { 
    public void done(ParseException e) { 
    if (e == null) { 
     // Hooray! Let them use the app now. 
    } else { 
     // Sign up didn't succeed. Look at the ParseException 
     // to figure out what went wrong 
    } 
    } 
}); 

这个解决方案的一个重要的事情:

不安全的做法是仅在您的应用中使用基于ID的ID /密码,更好的解决方案是将Google+ Token/UserId发送到后端/云端,然后后端/云端验证此Token/Id是否有效,然后创建用户名/密码,并与解析用户交换。

我希望你有想法。

+0

我如何发送Google+令牌? 我如何创建与会话令牌关联的新用户帐户? – 2015-05-24 00:29:43