Пример #1
0
  private String getAccessToken() {

    FacebookSdk.sdkInitialize(StudentAssistApplication.getAppContext());

    if (AccessToken.getCurrentAccessToken() != null
        && !AccessToken.getCurrentAccessToken().isExpired()) {
      String fbToken = AccessToken.getCurrentAccessToken().getToken();
      return fbToken;
    }

    return "";
  }
Пример #2
0
  private void setupViewObjects(User user) {
    ivCoverPic = (ImageView) mFragmentView.findViewById(R.id.ivCoverPic);
    ivProfilePic = (ImageView) mFragmentView.findViewById(R.id.ivProfilePic);
    TextView tvProfileName = (TextView) mFragmentView.findViewById(R.id.tvProfileName);
    TextView tvProfileLocation = (TextView) mFragmentView.findViewById(R.id.tvProfileLocation);

    Picasso.with(getContext())
        .load(
            "https://graph.facebook.com/"
                + user.getAuthId()
                + "/picture?width="
                + String.valueOf(getContext().getResources().getDisplayMetrics().widthPixels))
        .into(ivProfilePic /*new Target() {
                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        src = bitmap;
                        Resources res = getResources();
                        RoundedBitmapDrawable dr =
                                RoundedBitmapDrawableFactory.create(res, src);
                        dr.setCornerRadius(500f);
                        ivProfilePic.setImageDrawable(dr);
                    }

                    @Override
                    public void onBitmapFailed(Drawable errorDrawable) {

                    }

                    @Override
                    public void onPrepareLoad(Drawable placeHolderDrawable) {

                    }
                }*/);

    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {

              @Override
              public void onCompleted(JSONObject ret, GraphResponse graphResponse) {
                JSONObject cover = null;
                String url = null;
                try {
                  cover = ret.getJSONObject("cover");
                  url = cover.getString("source");
                } catch (JSONException e) {
                  e.printStackTrace();
                }
                Picasso.with(getContext()).load(url).into(ivCoverPic);
              }
            });

    Bundle parameters = new Bundle();
    parameters.putString("fields", "cover");
    request.setParameters(parameters);
    request.executeAsync();

    tvProfileName.setText(user.getName());
  }
Пример #3
0
  private void getUserDetailsFromFB() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                try {
                  userNameText = jsonObject.getString("name");
                } catch (JSONException e) {
                  e.printStackTrace();
                }
                try {
                  emailId = jsonObject.getString("email");
                } catch (JSONException e) {
                  e.printStackTrace();
                }

                saveNewUser();
              }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "name,email");
    request.setParameters(parameters);
    request.executeAsync();
  }
  /** {@inheritDoc} */
  public void reloadUserInfo() {
    clearUserInfo();
    if (!isUserSignedIn()) {
      return;
    }

    final Bundle parameters = new Bundle();
    parameters.putString("fields", "name,picture.type(large)");
    final GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), "me");
    graphRequest.setParameters(parameters);
    GraphResponse response = graphRequest.executeAndWait();

    JSONObject json = response.getJSONObject();
    try {
      userName = json.getString("name");
      userImageUrl = json.getJSONObject("picture").getJSONObject("data").getString("url");

    } catch (final JSONException jsonException) {
      Log.e(
          LOG_TAG,
          "Unable to get Facebook user info. " + jsonException.getMessage() + "\n" + response,
          jsonException);
      // Nothing much we can do here.
    }
  }
Пример #5
0
  private void getUserDetailsFromFB() {

    new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/me",
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
              public void onCompleted(GraphResponse response) {
                /* handle the result */
                try {
                  email = response.getJSONObject().getString("email");
                  mEmailID.setText(email);
                  name = response.getJSONObject().getString("name");
                  mUsername.setText(name);

                  saveNewUser();
                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            })
        .executeAsync();

    ProfilePhotoAsync profilePhotoAsync = new ProfilePhotoAsync(mFbProfile);
    profilePhotoAsync.execute();
  }
 private void performPublish(PendingAction action, boolean allowNoToken) {
   AccessToken accessToken = AccessToken.getCurrentAccessToken();
   if (accessToken != null || allowNoToken) {
     mPendingAcction = action;
     handlePedingAcction();
   }
 }
Пример #7
0
 private void getUserDetailsFromFB() {
   Bundle parameters = new Bundle();
   // add "birthday" if app has been reviewed for user_birthday permission by Facebook
   parameters.putString("fields", "email,name,picture");
   new GraphRequest(
           AccessToken.getCurrentAccessToken(),
           "/me",
           parameters,
           HttpMethod.GET,
           new GraphRequest.Callback() {
             public void onCompleted(GraphResponse response) {
               /* handle the result */
               try {
                 email = response.getJSONObject().getString("email");
               } catch (JSONException e) {
                 // The user has refused to give the app their email through Fb
                 email = "";
               }
               try {
                 name = response.getJSONObject().getString("name");
                 Log.e(LOG_TAG, "name is " + name + " and email is " + email);
                 JSONObject picture = response.getJSONObject().getJSONObject("picture");
                 JSONObject data = picture.getJSONObject("data");
                 //  Returns a 50x50 profile picture
                 String pictureUrl = data.getString("url");
                 new ProfilePhotoAsync(pictureUrl).execute();
               } catch (JSONException e) {
                 e.printStackTrace();
               }
             }
           })
       .executeAsync();
 }
Пример #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);
    nameText = (TextView) findViewById(R.id.text_name);
    dataList = (ListView) findViewById(R.id.list_data);
    contentButton = (Button) findViewById(R.id.content_button);
    fbbutton = (LoginButton) findViewById(R.id.login_button);

    fbbutton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onFblogin();
          }
        });
    if (AccessToken.getCurrentAccessToken() != null) {
      contentButton.setVisibility(View.VISIBLE);
      contentButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              access_token = AccessToken.getCurrentAccessToken();
              getFacebookData();
            }
          });
    }
  }
 /**
  * Returns a request to delete a like on an object.
  *
  * @param objectId The id of the object.
  * @param listener The callback events listener.
  */
 public FBDeleteLikeRequest generateDeleteLikeRequest(
     String objectId, OnLikeRequestListener listener) {
   FBDeleteLikeRequest request = new FBDeleteLikeRequest(AccessToken.getCurrentAccessToken());
   request.setTarget(objectId);
   request.setGraphRequestListener(listener);
   return request;
 }
Пример #10
0
 private void setButtonText() {
   final Resources resources = getResources();
   if (!isInEditMode() && AccessToken.getCurrentAccessToken() != null) {
     setText(
         (logoutText != null)
             ? logoutText
             : resources.getString(R.string.com_facebook_loginview_log_out_button));
   } else {
     if (loginText != null) {
       setText(loginText);
     } else {
       String text = resources.getString(R.string.com_facebook_loginview_log_in_button_long);
       int width = getWidth();
       // if the width is 0, we are going to measure size, so use the long text
       if (width != 0) {
         // we have a specific width, check if the long text fits
         int measuredWidth = measureButtonWidth(text);
         if (measuredWidth > width) {
           // it doesn't fit, use the shorter text
           text = resources.getString(R.string.com_facebook_loginview_log_in_button);
         }
       }
       setText(text);
     }
   }
 }
 /**
  * Create a Facebook Response object that matches the one for the Javascript SDK
  *
  * @return JSONObject - the response object
  */
 public JSONObject getResponse() {
   String response;
   final AccessToken accessToken = AccessToken.getCurrentAccessToken();
   if (hasAccessToken()) {
     Date today = new Date();
     long expiresTimeInterval = (accessToken.getExpires().getTime() - today.getTime()) / 1000L;
     response =
         "{"
             + "\"status\": \"connected\","
             + "\"authResponse\": {"
             + "\"accessToken\": \""
             + accessToken.getToken()
             + "\","
             + "\"expiresIn\": \""
             + Math.max(expiresTimeInterval, 0)
             + "\","
             + "\"session_key\": true,"
             + "\"sig\": \"...\","
             + "\"userID\": \""
             + accessToken.getUserId()
             + "\""
             + "}"
             + "}";
   } else {
     response = "{" + "\"status\": \"unknown\"" + "}";
   }
   try {
     return new JSONObject(response);
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return new JSONObject();
 }
  public void requestFacebookUserDetails() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject profile, GraphResponse response) {
                // JSONObject userProfile = new JSONObject();
                if (profile == null) {
                  Log.wtf("FIRST", "PROFILE VAZIO");
                } else {
                  ParseUser currentUser = ParseUser.getCurrentUser();
                  try {
                    currentUser.put("name", profile.get("name"));
                    currentUser.saveInBackground();
                    goToHomePage();
                  } catch (JSONException e) {
                    Log.wtf("ERROR DETAIL", "Erro ao pegar detalhes");
                  }
                }
              }
            });

    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,picture,name,link");
    request.setParameters(parameters);
    request.executeAsync();
  }
  private void readPost() {
    AccessToken token = AccessToken.getCurrentAccessToken();
    String path = "/me/feed";
    GraphRequest request =
        new GraphRequest(
            token,
            path,
            null,
            HttpMethod.GET,
            new Callback() {

              @Override
              public void onCompleted(GraphResponse response) {
                JSONObject obj = response.getJSONObject();
                if (obj != null) {
                  Toast.makeText(
                          MainActivity.this, "result : " + obj.toString(), Toast.LENGTH_SHORT)
                      .show();
                } else {
                  Toast.makeText(
                          MainActivity.this,
                          "errof : " + response.getError().getErrorMessage(),
                          Toast.LENGTH_SHORT)
                      .show();
                }
              }
            });
    request.executeAsync();
  }
Пример #14
0
  public boolean getBeepleImages() {
    currentToken = AccessToken.getCurrentAccessToken();
    if (currentToken != null) {
      GraphRequest request =
          GraphRequest.newGraphPathRequest(
              currentToken,
              "/10150428845566781/photos",
              new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                  JSONObject data = response.getJSONObject();
                  try {
                    String newestImage = data.getJSONArray("data").getJSONObject(0).getString("id");
                    getImage(newestImage);
                    Log.d(TAG, newestImage);
                  } catch (org.json.JSONException e) {
                    Log.e(TAG, e.toString());
                  }
                }
              });

      request.executeAsync();
      return true;
    } else {
      Log.d(TAG, "Current access token does not exist");
      return false;
    }
  }
  public void RequestData() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject object, GraphResponse response) {

                JSONObject json = response.getJSONObject();
                try {
                  if (json != null) {
                    String text =
                        "<b>Name :</b> "
                            + json.getString("name")
                            + "<br><br><b>Email :</b> "
                            + json.getString("email")
                            + "<br><br><b>Profile link :</b> "
                            + json.getString("link");
                    details_txt.setText(Html.fromHtml(text));
                    profile.setProfileId(json.getString("id"));
                  }

                } catch (JSONException e) {
                  e.printStackTrace();
                }
              }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link,email,picture");
    request.setParameters(parameters);
    request.executeAsync();
  }
Пример #16
0
 private void getFacebookId() {
   AccessToken accessToken = AccessToken.getCurrentAccessToken();
   GraphRequest request =
       GraphRequest.newMeRequest(
           accessToken,
           new GraphRequest.GraphJSONObjectCallback() {
             @Override
             public void onCompleted(JSONObject object, GraphResponse response) {
               JSONObject result = response.getJSONObject();
               try {
                 String id = result.getString("id");
                 ParseUser user = ParseUser.getCurrentUser();
                 user.put("facebookId", id);
                 try {
                   user.save();
                 } catch (ParseException e) {
                   e.printStackTrace();
                 }
               } catch (JSONException e) {
                 e.printStackTrace();
               }
             }
           });
   Bundle parameters = new Bundle();
   parameters.putString("fields", "id");
   request.setParameters(parameters);
   request.executeAsync();
 }
Пример #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_make_post);

    LoginManager.getInstance().registerCallback(mCallbackManager, this);
    if (!AccessToken.getCurrentAccessToken()
        .getPermissions()
        .contains(FacebookConstant.PERMISSION_PUBLISH_ACTIONS)) {
      LoginManager.getInstance()
          .logInWithPublishPermissions(
              CreatePostActivity.this,
              new ArrayList<String>() {
                {
                  add(FacebookConstant.PERMISSION_PUBLISH_ACTIONS);
                }
              });
    } else {
      mPostButton.setEnabled(true);
    }

    mPostText = (EditText) findViewById(R.id.post_text);
    mPostButton = (Button) findViewById(R.id.post_button);
    mPostButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            FacebookUtil.postToWall(mPostText.getText().toString(), CreatePostActivity.this);
          }
        });
  }
 {
     this$0 = LikeActionController.this;
     super(LikeActionController.this, s, r);
     likeactioncontroller = new Bundle();
     putString("object", s);
     setRequest(new GraphRequest(AccessToken.getCurrentAccessToken(), "me/og.likes", LikeActionController.this, HttpMethod.POST));
 }
 /**
  * Returns a request to publish a comment.
  *
  * @param objectId The id of the post or comment.
  * @param comment The comment's message.
  * @param listener The callback events listener.
  */
 public FBPostCommentRequest generatePostCommentRequest(
     String objectId, String comment, OnPostCommentListener listener) {
   FBPostCommentRequest request = new FBPostCommentRequest(AccessToken.getCurrentAccessToken());
   request.setTarget(objectId);
   request.setProperties(comment);
   request.setGraphRequestListener(listener);
   return request;
 }
 /**
  * Returns a request to fetch a single comment details.
  *
  * @param commentId
  * @param listener The callback events listener.
  */
 public FBGetCommentRequest generateGetCommentRequest(
     String commentId, OnGetCommentListener listener) {
   FBGetCommentRequest request = new FBGetCommentRequest(AccessToken.getCurrentAccessToken());
   request.setTarget(commentId);
   request.setProperties(FBGraphUtils.COMMENT_FIELDS);
   request.setGraphRequestListener(listener);
   return request;
 }
 /**
  * Returns a request to fetch a set of comments.
  *
  * @param objectId The target ID (post or comment).
  * @param limit The size of the comments list.
  * @param after The offset value.
  * @param listener The callback events listener.
  */
 public FBGetCommentsRequest generateGetCommentsRequest(
     String objectId, int limit, final String after, OnGetCommentsListener listener) {
   FBGetCommentsRequest request = new FBGetCommentsRequest(AccessToken.getCurrentAccessToken());
   request.setTarget(objectId);
   request.setProperties(
       FBGraphUtils.COMMENT_FIELDS, FBGraphUtils.COMMENTS_ORDER.CHRONOLOGICAL, limit, after);
   request.setGraphRequestListener(listener);
   return request;
 }
  @Override
  boolean tryAuthorize(final LoginClient.Request request) {
    Bundle parameters = new Bundle();
    if (!Utility.isNullOrEmpty(request.getPermissions())) {
      String scope = TextUtils.join(",", request.getPermissions());
      parameters.putString(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
      addLoggingExtra(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
    }

    DefaultAudience audience = request.getDefaultAudience();
    parameters.putString(
        ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE, audience.getNativeProtocolAudience());

    AccessToken previousToken = AccessToken.getCurrentAccessToken();
    String previousTokenString = previousToken != null ? previousToken.getToken() : null;
    if (previousTokenString != null && (previousTokenString.equals(loadCookieToken()))) {
      parameters.putString(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, previousTokenString);
      // Don't log the actual access token, just its presence or absence.
      addLoggingExtra(
          ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, AppEventsConstants.EVENT_PARAM_VALUE_YES);
    } else {
      // The call to clear cookies will create the first instance of CookieSyncManager if
      // necessary
      Utility.clearFacebookCookies(loginClient.getActivity());
      addLoggingExtra(
          ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, AppEventsConstants.EVENT_PARAM_VALUE_NO);
    }

    WebDialog.OnCompleteListener listener =
        new WebDialog.OnCompleteListener() {
          @Override
          public void onComplete(Bundle values, FacebookException error) {
            onWebDialogComplete(request, values, error);
          }
        };

    e2e = LoginClient.getE2E();
    addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);

    FragmentActivity fragmentActivity = loginClient.getActivity();
    WebDialog.Builder builder =
        new AuthDialogBuilder(fragmentActivity, request.getApplicationId(), parameters)
            .setE2E(e2e)
            .setIsRerequest(request.isRerequest())
            .setReauthenticate(request.isReauthenticate())
            .setOnCompleteListener(listener)
            .setTheme(FacebookSdk.getWebDialogTheme());
    loginDialog = builder.build();

    FacebookDialogFragment dialogFragment = new FacebookDialogFragment();
    dialogFragment.setRetainInstance(true);
    dialogFragment.setDialog(loginDialog);
    dialogFragment.show(fragmentActivity.getSupportFragmentManager(), FacebookDialogFragment.TAG);

    return true;
  }
  /** @return the Facebook AccessToken when signed-in with a non-expired token. */
  private AccessToken getSignedInToken() {
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if (accessToken != null && !accessToken.isExpired()) {
      Log.d(LOG_TAG, "Facebook Access Token is OK");
      return accessToken;
    }

    Log.d(LOG_TAG, "Facebook Access Token is null or expired.");
    return null;
  }
  private void uploadUserDetails(String registrationId, String instanceId) {

    SharedPreferences sharedPreferences =
        StudentAssistApplication.getAppContext()
            .getSharedPreferences(SAConstants.sharedPreferenceName, 0);

    // setting GCM id to user and storing it into shared preferences
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(SAConstants.GCM_ID, registrationId);
    editor.putString(SAConstants.INSTANCE_ID, instanceId);
    editor.commit();

    String fbToken = "";

    if (AccessToken.getCurrentAccessToken() != null
        && !AccessToken.getCurrentAccessToken().isExpired()) {

      fbToken = AccessToken.getCurrentAccessToken().getToken();
    } else {
      Toast.makeText(StudentAssistApplication.getAppContext(), "not registered", Toast.LENGTH_LONG)
          .show();
    }

    UrlInterface urlGen = new UrlGenerator();
    try {

      String url = urlGen.createUser(fbToken, instanceId);

      new NotificationBO(
          new NotificationBI() {
            @Override
            public void onResponse(String response) {

              L.m("successfully created user");
            }
          },
          url);

    } catch (Exception e) {
      ErrorReporting.logReport(e);
    }
  }
 private void toNextScreen() {
   if (AccessToken.getCurrentAccessToken() != null) {
     Intent loginWithFb = new Intent(SplashScreenActivity.this, MainMenuActivity.class);
     /*Intent loginWithFb = new Intent(SplashScreenActivity.this, MainActivity.class);*/
     startActivity(loginWithFb);
     finish();
   } else {
     Intent i = new Intent(SplashScreenActivity.this, FormLoginActivity.class);
     startActivity(i);
     finish();
   }
 }
Пример #26
0
 @Override
 public void run() {
   if (AccessToken.getCurrentAccessToken() != null) {
     Intent i = new Intent(mContext, EventListActivity.class);
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
     startActivity(i);
   } else {
     Intent i = new Intent(mContext, LoginActivity.class);
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
     startActivity(i);
   }
 }
 protected void signOutOfAccount() { // logout user completely, remove all login information
   SharedPreferences settings = getSharedPreferences("PosseUpData", MODE_PRIVATE);
   SharedPreferences.Editor editor = settings.edit();
   editor.remove("access_token");
   editor.remove("email");
   editor.remove("username");
   editor.remove("profileImageURL");
   editor.apply();
   AccessToken accessToken = AccessToken.getCurrentAccessToken();
   if (accessToken != null) {
     LoginManager.getInstance().logOut();
   }
 }
Пример #28
0
 private void verifyFbProfile(Profile profile) {
   LoginActivity.isFacebook = true;
   SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
   editor.putString(
       Constants.SHARED_PREFS_ACCESS_TOKEN, AccessToken.getCurrentAccessToken().toString());
   editor.apply();
   Intent i = new Intent(getApplicationContext(), MainActivity.class);
   startActivity(i);
   finish();
   Toast.makeText(
           getApplicationContext(), "Logged in as : " + profile.getFirstName(), Toast.LENGTH_LONG)
       .show();
 }
Пример #29
0
  private void refreshFriends() {
    GraphRequest req =
        new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/me/friends",
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
              @Override
              public void onCompleted(GraphResponse response) {
                Log.d("PartyOn", "Graphresponse: " + response.toString());
                if (response.getJSONArray() == null && response.getJSONObject() == null) return;
                try {
                  JSONArray data = response.getJSONObject().getJSONArray("data");

                  realm.beginTransaction();

                  Friend friend;
                  for (int i = 0; i < data.length(); i++) {
                    friend = new Friend();
                    friend.setId(data.getJSONObject(i).getString("id"));
                    friend.setName(data.getJSONObject(i).getString("first_name"));
                    friend.setImageUrl(
                        data.getJSONObject(i)
                            .getJSONObject("picture")
                            .getJSONObject("data")
                            .getString("url"));
                    realm.copyToRealmOrUpdate(friend);
                  }

                  realm.commitTransaction();

                  RealmResults<Friend> results = realm.allObjects(Friend.class); // TODO: Run async

                  if (!compact) {
                    getListView().setVisibility(View.VISIBLE);
                    progressBar.setVisibility(View.GONE);
                  }

                  adapter.update(results);
                } catch (JSONException e) {
                  Log.d("PartyOn", "JSON", e);
                  realm.cancelTransaction();
                }
              }
            });
    Bundle args = new Bundle();
    args.putString("fields", "id,first_name,picture");
    req.setParameters(args);
    req.executeAsync();
  }
Пример #30
0
  private void makeMeRequest() {
    GraphRequest request =
        GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject user, GraphResponse response) {
                if (user != null) {

                  JSONObject userProfile = new JSONObject();
                  try {

                    // profilePicture.setProfileId(user.getString("id"));

                    userProfile.put("facebookId", user.getLong("id"));
                    userProfile.put("name", user.getString("name"));
                    if (user.getString("gender") != null) {
                      userProfile.put("gender", (String) user.getString("gender"));
                    }
                    if (user.getString("email") != null) {
                      userProfile.put("email", (String) user.getString("email"));
                    }

                    ParseUser currentUser = ParseUser.getCurrentUser();
                    currentUser.put("name", user.getString("name"));
                    currentUser.put("type", "User");
                    currentUser.put("profile", userProfile);

                  } catch (JSONException e) {
                    Log.d("My", "Error parsing returned user data. " + e);
                  }

                } else if (response.getError() != null) {
                  switch (response.getError().getCategory()) {
                    case LOGIN_RECOVERABLE:
                      Log.d("theSOS", "Authentication error: " + response.getError());
                      break;

                    case TRANSIENT:
                      Log.d("theSOS", "Transient error. Try again. " + response.getError());
                      break;

                    case OTHER:
                      Log.d("theSOS", "Some other error: " + response.getError());
                      break;
                  }
                }
              }
            });
    request.executeAsync();
  }