2017-08-10 23 views
0

Facebookを使用中にParse-Serverにサインアップする際に問題が発生しています。 Facebookのアイコンが付いたサインアップをユーザーがクリックすると、このコードは...Parse-Server Facebookログイン

ParseFacebookUtils.logInWithReadPermissionsInBackground(LoginRegister.this, permissions, new LogInCallback() { 
    @Override 
    public void done(ParseUser user, ParseException err) { 
     if (user == null) { 
      MethodContants.showLog(TAG, "Uh oh. The user cancelled the Facebook login.", true); 
     } else if (user.isNew()) { 
      MethodContants.showLog(TAG, "User logged in through Facebook", false); 
      getUserDetailsFromFacebook(); 
     } else { 
      MethodContants.showLog(TAG, "User logged in through Facebook", false); 
      Intent intent = new Intent(LoginRegister.this, MainActivity.class); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
      startActivity(intent); 
     } 
    } 
}); 

マイgetUserDetailsFromFacebook()メソッドを実行します

この

private void getUserDetailsFromFacebook() { 
    GraphRequest graphRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() { 
     @Override 
     public void onCompleted(JSONObject jsonObject, GraphResponse response) { 

      try { 
       facebookUser = jsonObject.getString("name"); 
       MethodContants.showLog(TAG, "json name object: " + jsonObject.getString("name"), false); 
      } catch (JSONException e) { 
       MethodContants.showLog(TAG, "Error when getting facebook name: " + e.getMessage(), true); 
       showToast("Error saving Facebook user."); 
      } 
      try { 
       facebookEmail = jsonObject.getString("email"); 
       MethodContants.showLog(TAG, "json email object: " + jsonObject.getString("email"), false); 
      } catch (JSONException e) { 
       MethodContants.showLog(TAG, "Error when getting facebook email: " + e.getMessage(), true); 
       showToast("Error saving Facebook email."); 
      } 
      saveNewFacebookUser(); 
     } 
    }); 

    Bundle parameters = new Bundle(); 
    parameters.putString("fields", "name,email"); 
    graphRequest.setParameters(parameters); 
    graphRequest.executeAsync(); 

} 

私saveNewFacebookUser(ように見える)、このようになります。 ...

private void saveNewFacebookUser() { 
    final ParseUser newFacebookUser = new ParseUser(); 
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.profile_picture); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 
    byte[] image = stream.toByteArray(); 
    ParseFile file = new ParseFile(AppConstants.PARSEUSER_IMAGE_FILE_NAME, image); 
    newFacebookUser.setUsername(facebookUser); 
    newFacebookUser.setEmail(facebookEmail); 
    newFacebookUser.put(AppConstants.PARSEUSER_FULLNAME, facebookUser); 
    newFacebookUser.put(AppConstants.PARSEUSER_FIRST_TIME_LOGGED_IN, "true"); 
    newFacebookUser.put(AppConstants.PARSEUSER_PROFILE_IMAGE, file); 

    file.saveInBackground(new SaveCallback() { 
     @Override 
     public void done(ParseException e) { 
      if (e == null) { 
       newFacebookUser.saveInBackground(new SaveCallback() { 
        @Override 
        public void done(ParseException e) { 
         if (e == null) { 
          // USER CREATED! 
          // TODO SEND AN EMAIL TO THE USER WITH USERNAME AND PASSWORD 
          Intent intent = new Intent(LoginRegister.this, MainActivity.class); 
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
          intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
          startActivity(intent); 
         } else { 
          MethodContants.showLog(TAG, "Facebook Error:" + e.getMessage(), true); 
          showToast("Facebook Error: " + e.getMessage()); 
         } 
        } 
       }); 
      } else { 
       MethodContants.showLog(TAG, "Facebook Error:" + e.getMessage(), true); 
       showToast("Facebook Error: " + e.getMessage()); 
      } 
     } 
    }); 
} 

エラーが表示されるのは、sig nUpInBackgroundで、saveInBackgroundではありません。しかし、私がそれをすると、私はユーザーのパスワードを保存する必要があるという別のエラーが出ます - これはFacebookのログインの目的全体を打ち負かします。

ご協力いただければ幸いです。

答えて

0

問題が見つかりました。

saveNewFacebookUser()メソッドでは、新しいユーザーとして設定していました。

ParseUser new = new ParseUser(); 

これは

ParseUser new = ParseUser.getCurrentUser(); 

されている必要があります誰もが問題を持っている場合には、私はこれを残します。