private void signInFB() { List<String> permissions = Arrays.asList( "public_profile", "email"); ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(), permissions, new LogInCallback() { @Override public void done(ParseUser parseUser, ParseException e) { Log.d(TAG, "logInWithReadPermissionsInBackground done"); if (e == null) { boolean fullyRegistered = parseUser.getBoolean(ParseTables.Users.FULLY_REGISTERED); if (parseUser == null) Log.d("MyApp", "Uh oh. The user cancelled the Facebook login."); else if(!fullyRegistered || parseUser.isNew()) { getFacebookData(); } else { Utils.goToMainActivity(getActivity()); } } else { e.printStackTrace(); } } }); }
private void setUpFacebookLogin() { facebookLoginButton.setVisibility(View.VISIBLE); if (config.getFacebookLoginButtonText() != null) { facebookLoginButton.setText(config.getFacebookLoginButtonText()); } facebookLoginButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { loadingStart(false); // Facebook login pop-up already has a spinner if (config.isFacebookLoginNeedPublishPermissions()) { ParseFacebookUtils.logInWithPublishPermissionsInBackground(getActivity(), config.getFacebookLoginPermissions(), facebookLoginCallbackV4); } else { ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(), config.getFacebookLoginPermissions(), facebookLoginCallbackV4); } } }); }
private void setupParse() { Parse.initialize(this, getString(R.string.parse_app_id), getString(R.string.parse_client_key)); ParseFacebookUtils.initialize(this); if(ParseUser.getCurrentUser() != null && !UserPreferences.isUserAssociatedWithInstallation()) { // This should be done only once ParseInstallation currentInstallation = ParseInstallation.getCurrentInstallation(); currentInstallation.put("user", ParseUser.getCurrentUser()); currentInstallation.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e != null) { Timber.d("Error when trying to associate user with installation: " + e.getLocalizedMessage()); } else { Timber.d("User successfully associated with installation"); UserPreferences.setUserAssociatedWithInstallation(); } } }); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.w(TAG, "onActivityResult called"); if (requestCode == RC_SIGN_IN) { if (resultCode != -1) { mSignInClicked = false; } mIntentInProgress = false; if (!mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } } ParseFacebookUtils.onActivityResult(requestCode, resultCode, data); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); loginButton = (Button) findViewById(R.id.loginButton); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(AnypicApplication.TAG, "Login button clicked"); onLoginButtonClicked(); } }); // Check if there is a currently logged in user // and they are linked to a Facebook account. ParseUser currentUser = ParseUser.getCurrentUser(); if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) { // Go to the main photo list view activity showHomeListActivity(); } // For push notifications ParseAnalytics.trackAppOpened(getIntent()); }
private void onLoginButtonClicked() { LoginActivity.this.progressDialog = ProgressDialog.show( LoginActivity.this, "", "Logging in...", true); List<String> permissions = Arrays.asList("public_profile","user_about_me","user_friends"); ParseFacebookUtils.logIn(permissions, this, new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { LoginActivity.this.progressDialog.dismiss(); if (user == null) { Log.i(AnypicApplication.TAG, "Uh oh. The user cancelled the Facebook login."); } else if (user.isNew()) { Log.i(AnypicApplication.TAG, "User signed up and logged in through Facebook!"); showHomeListActivity(); } else { Log.i(AnypicApplication.TAG, "User logged in through Facebook!"); showHomeListActivity(); } } }); }
public void retrieveEmailAddress() { Request request = Request.newMeRequest(ParseFacebookUtils.getSession(), new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { try { String email = user.getInnerJSONObject().get("email").toString(); ParseUser.getCurrentUser().setEmail(email); ParseUser.getCurrentUser().saveEventually(); } catch (JSONException e) { Log.e("CatChatInbox", "Failed to parse JSON from FB", e); } } } } ); request.executeAsync(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && requestCode == CONTACT_PICKER_RESULT) { Contact c = getEmailAddress(data); if (c != null) { sendMessage("toEmail", c.email()); } } else if (resultCode == RESULT_OK && requestCode == PICK_FB_CONTACT) { String fbId = data.getExtras().getString("fbid"); if (!TextUtils.isEmpty(fbId)) { sendMessage("toFacebook", fbId); } } else if (resultCode == RESULT_OK && requestCode == 32665) { ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data); } else { super.onActivityResult(requestCode, resultCode, data); } }
private void ensureUserIsLoggedInToFacebookAndPresentFriendPicker() { Session fbSession = Session.getActiveSession(); if (fbSession == null || !fbSession.isOpened() || !ParseFacebookUtils.isLinked(ParseUser.getCurrentUser())) { mProgressDialog = CatProgressDialog.show(SendCatMessageActivity.this, getString(R.string.logging_in)); final List<String> permissions = Utils.getFBPermissions(); ParseFacebookUtils.link(ParseUser.getCurrentUser(), permissions, SendCatMessageActivity.this, new SaveCallback() { @Override public void done(ParseException e) { SendCatMessageActivity.this.mProgressDialog.dismiss(); presentFriendPicker(); } }); } else { presentFriendPicker(); } }
private void onLoginButtonClicked() { mProgressDialog = CatProgressDialog.show(MainActivity.this, getString(R.string.logging_in)); List<String> permissions = Utils.getFBPermissions(); ParseFacebookUtils.logIn(permissions, this, new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { MainActivity.this.mProgressDialog.dismiss(); if (user == null) { Log.d("CatChatLogin", "User cancelled Facebook login"); } else { if(currentUserHasNoEmailAddress()) { ((CatChatApplication)getApplication()).retrieveEmailAddress(); } Utils.mapInstallationToCurrentUser(); showInboxActivity(); } } }); }
/** * Shows the profile of the given user. * * @param user */ private void showProfile(ParseUser user) { if (user != null) { String fullName = user.getString("name"); String email = user.getString("email"); getActionBar().setTitle("Profile"); boolean isFacebookLinkedUser=ParseFacebookUtils.isLinked(user); email = user.getString("email"); if (isFacebookLinkedUser) { setEmail(); } else { showDonorInformaiton(fullName,email,false); } } }
public void setEmail() { Request.newMeRequest(ParseFacebookUtils.getSession(), new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { ImageLoader imgImageLoader = ImageLoader.getInstance(); imgImageLoader.displayImage( "http://graph.facebook.com/" + user.getId() + "/picture?type=large", profilePicture); String email = user.asMap().get("email").toString(); showDonorInformaiton(user.getName(),email,true); } }).executeAsync(); }
private void createBuyerChannel() { final Session session = ParseFacebookUtils.getSession(); if (session != null && session.isOpened()) { Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (session == Session.getActiveSession()) { if (user != null) { facebookId = user.getId(); String c = buyerProfile != null ? buyerProfile + adId : facebookId + adId; subscribeChannel(c); publishMessage(c, facebookId, adId); } } } }); Request.executeBatchAsync(request); } }
public void getPhotos(){ new Request( ParseFacebookUtils.getSession(), "/me/photos", null, HttpMethod.GET, new Request.Callback() { public void onCompleted(Response response) { GraphObject obj = response.getGraphObject(); JSONArray array =(JSONArray) obj.getProperty("data"); //Only save valid photo array if(array != null && array.length() > 0) { ParseUser.getCurrentUser().put(Enums.ParseKey.USER_FB_PHOTOS, array.toString()); ParseUser.getCurrentUser().saveInBackground(); } } } ).executeAsync(); }
@Override public void onCreate() { super.onCreate(); Parse.initialize(this, "aTAL8FkWWQRG2bsilzCzwQpVMY2YCK8skFryZIFa", "vLefUWhxBk12E8X4oighFYt25iGnMYRTUP58RDJg"); ParseFacebookUtils.initialize(getString(R.string.app_id)); PushService.setDefaultPushCallback(this, ViewActivity.class); ParseInstallation.getCurrentInstallation().saveInBackground(); if (BuildConfig.DEBUG) { Timber.plant(new DebugTree()); } else { // TODO Crashlytics.start(this); // TODO Timber.plant(new CrashlyticsTree()); } applicationGraph = ObjectGraph.create(getModules().toArray()); }
@Override protected void onResume(){ super.onResume(); if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) { //user logged in through facebook try { if(currentUser.has("myPetProfile")){ petProfile = currentUser.getParseObject("myPetProfile").fetchIfNeeded(); profilePicture = petProfile.getParseFile("profilePicture"); } Log.d(TAG, "retrieved petProfile"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.d(TAG,"error fetching"); } getParseUserData(); } else { Log.d(TAG,"user not logged in"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Parse.initialize(this, "bl9sFBxmrkDhNWSDxnlvbLIbeFrQ9kHUGEbBRI4a", "tCzPn6RbPx2ZJUmGc7AMb2eBoetXgO02A4jefTHp"); ParseFacebookUtils.initialize(getString(R.string.facebook_app_id)); setContentView(R.layout.activity_main); //define intents settingsIntent = new Intent(this, SettingsActivity.class); gps = new GPSManager(MainActivity.this); // register buttons loginButton = (Button) findViewById(R.id.facebookLoginButton); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onLoginButtonClicked(); } }); Log.d(TAG, "Called onCreate"); }
@Override protected void onResume(){ super.onResume(); if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) { //user logged in through facebook try { if (currentUser.has("myPetProfile")){ petProfile = currentUser.getParseObject("myPetProfile").fetchIfNeeded(); } Log.d(TAG, "retrieved petProfile"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.d(TAG,"error fetching"); } getParseUserData(); } else { Log.d(TAG,"user not logged in"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_settings); //define intents mainIntent = new Intent(this, MainActivity.class); deleteButton = (Button) findViewById(R.id.delete_account_button); deleteButton.setOnClickListener(delete); logoutButton = (Button) findViewById(R.id.logout_button); logoutButton.setOnClickListener(logout); // Check if there is a currently logged in user // and it's linked to a Facebook account. currentUser = ParseUser.getCurrentUser(); profilePic = (ProfilePictureView) findViewById(R.id.facebookProfilePic); profileName = (TextView) findViewById(R.id.facebookProfileName); if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) { makeMeRequest(); } else { logoutButton.setVisibility(View.INVISIBLE); } Log.d(TAG, "Called OnCreate"); }
private void saveFacebookInfo() { Request request = Request.newMeRequest(ParseFacebookUtils.getSession(), new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser graphUser, Response response) { if (graphUser != null) { new DownloadProfilePictureTask().execute(new String[] { graphUser.getId(), graphUser.getName() }); } else if (response.getError() != null) { if ((response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_RETRY) || (response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_REOPEN_SESSION)) { Log.d(LOG_TAG, "The facebook session was invalidated."); } else { Log.e(LOG_TAG, "Some other error: " + response.getError().getErrorMessage()); } } } }); request.executeAsync(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); loginButton = (LoginButton) findViewById(R.id.login); //Make button disapear when clicked //TODO add a loading animation loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FBlogin(); //loginButton.setVisibility(View.INVISIBLE); } }); if ((currentUser != null) && ParseFacebookUtils.isLinked(currentUser)) { // Go to the user info activity Intent intent = new Intent(LoginActivity.this, GameScreenActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }
private static void getFacebookInfoInBackground() { Request.newMeRequest(ParseFacebookUtils.getSession(), new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { ParseUser.getCurrentUser().put("facebookId", user.getId()); ParseUser.getCurrentUser().put("fullName", user.getName()); ParseUser.getCurrentUser().put("firstName", user.getFirstName()); ParseUser.getCurrentUser().put("lastName", user.getLastName()); ParseUser.getCurrentUser().put("email", user.getProperty("email")); String imageURL = "https://graph.facebook.com/" + user.getId() + "/picture?width=200&height=200"; ParseUser.getCurrentUser().put("profilePictureURL", imageURL); ParseUser.getCurrentUser().saveInBackground(); } } }).executeAsync(); }
public static void facebookLogin(String fbAppId, Activity activity, final HTKCallback callback) { ParseHelper.fbInit(fbAppId); ParseFacebookUtils.logIn(Arrays.asList("email", Permissions.Friends.ABOUT_ME), activity, new LogInCallback() { @Override public void done(ParseUser parseUser, ParseException err) { if (parseUser == null) { Log.d("Hacktoolkit", "Uh oh. The user cancelled the Facebook login."); } else { HTKUser.getCurrentUser(parseUser).updateWithGraphUser(); if (parseUser.isNew()) { Log.d("Hacktoolkit", "User signed up and logged in through Facebook!"); } else { Log.d("Hacktoolkit", "User logged in through Facebook!"); } callback.execute(null); } } }); }
public void updateWithGraphUser() { Request.newMeRequest(ParseFacebookUtils.getSession(), new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { String fbId = user.getId(); String firstName = user.getFirstName(); String lastName = user.getLastName(); String email = (String) user.getProperty("email"); parseUser.put("fbId", fbId); parseUser.put("firstName", firstName); parseUser.put("lastName", lastName); parseUser.put("email", email); parseUser.saveEventually(); } } }).executeAsync(); }
public void loginFacebook(View view) { showActivityIndicator(); // network not available if (!Utils.isNetworkAvailable(getApplicationContext())) { Toast.makeText(getApplicationContext(), "Network not available", Toast.LENGTH_SHORT).show(); hideActivityIndicator(); return; } ParseFacebookUtils.initialize(ParseConsts.FACEBOOK_APP_ID); ParseFacebookUtils.logIn(this, new LogInCallback() { @Override public void done(ParseUser user, ParseException err) { hideActivityIndicator(); if (user == null) { Toast.makeText(getApplicationContext(), "Unable to login to facebook : " + err.getMessage(), Toast.LENGTH_SHORT).show(); } else { Utils.setCurrentUsername(user.getUsername()); saveInstallationID(); showHome(); } } }); }
@Override public void onCreate() { super.onCreate(); // [Optional] Power your app with Local Datastore. For more info, go to // https://parse.com/docs/android/guide#local-datastore Parse.enableLocalDatastore(this); Parse.initialize(this); FacebookSdk.sdkInitialize(getApplicationContext()); ParseFacebookUtils.initialize(this); }
@Override public void onCreate() { super.onCreate(); // parse stuff // Enable Local Datastore. Parse.enableLocalDatastore(this); Parse.initialize(this, "GxjbG5WjErNyikhLsG4Dmb276txlYmCsJg1onPgi", "keo5ziWIgz5txlDXqi4Xxx3DiVxcN1afaJzWNoa9"); ParseFacebookUtils.initialize(this); // firebase stuff Firebase.setAndroidContext(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_in); Button loginButton = (Button) findViewById(R.id.login_button); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List<String> permissions = new ArrayList<>(); permissions.add("user_birthday"); ParseFacebookUtils.logInWithReadPermissionsInBackground(SignInActivity.this, permissions, new LogInCallback() { @Override public void done(ParseUser parseUser, ParseException e) { if (parseUser == null) { Log.i(TAG, "User is null. Error creating user."); } else if (parseUser.isNew()) { Log.i(TAG, "User is new. Created new user."); getFacebookInfo(); } else { Log.i(TAG, "Logged in existing user."); setResult(RESULT_OK); finish(); } } }); } }); }
@Override public void onCreate() { super.onCreate(); Fresco.initialize(this); Parse.enableLocalDatastore(this); Parse.initialize(this, "Qkf0ETa2dogBX3ot1BgSswy09PR6fAK6vJEMGcof", "KqV8lTovHNQQPuZ819qzCHK617uXvJIkWpxaqLkf"); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); ParseFacebookUtils.initialize(this); ParseTwitterUtils.initialize("J3ncUDAVwYhOPRadv1kD7Z75G","bVSeScEZB8u7jFnLQmtk0FiCTdw1vIJJpfapTDrHDoVFLEOFCP"); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Required for making Facebook login work ParseFacebookUtils.onActivityResult(requestCode, resultCode, data); }
private void setUpFacebookLogin() { facebookLoginButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { loadingStart(false); // Facebook login pop-up already has a spinner ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(), ParseLoginConfig.fromBundle(getArguments(), getActivity()).getFacebookLoginPermissions(), facebookLoginCallbackV4); } }); }
@Nullable public String getUsername() { if(isLoggedIn()) { ParseUser currentUser = ParseUser.getCurrentUser(); if(ParseFacebookUtils.isLinked(currentUser)) { return currentUser.getString("name"); } else { return currentUser.getUsername(); } } else { return null; } }
@Override public void onCreate() { super.onCreate(); // Parse.enableLocalDatastore(this); Parse.initialize(this, "9nhyJ0OEkfqmGygl44OAYfdFdnapE27d9yj9UI5x", "7pJlc2KZgpFXZHwvoXwVeZUsEtiDoTrtjPM7EGBa"); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); ParseFacebookUtils.initialize(this); ParseTwitterUtils.initialize("FfUOeQ5OBuv0qOkdHbfXCrwdk", "xQmFnUSii54eS3iUrl0uIrxfeL4EfIdFc6iyoHUDgSIVGDbauD"); Fresco.initialize(this); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (DEBUG) Log.d(TAG, "onActivityResult called"); FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = fragmentManager.findFragmentByTag("SignOnFragment"); if (fragment != null) { fragment.onActivityResult(requestCode, resultCode,data); } ParseFacebookUtils.onActivityResult(requestCode, resultCode, data); }
@Override public void onCreate() { SharedPreferences sPref = getSharedPreferences("location", MODE_PRIVATE); currentLatitude = Double.valueOf(sPref.getString("lastLatitude", "28.6328")); currentLongitude = Double.valueOf(sPref.getString("lastLongitude", "77.2197")); Parse.initialize(this, "tA24P8ZHIuY6T6GCePmlwS94r7DKYIl0DrYee41g", "1pJVaZcK43AXO6wAtDzqPs1GMkA1E3jHtXTNCzKc"); ParseFacebookUtils.initialize(this); ParseTwitterUtils.initialize("PdLB1zaNjktVXpBqPddVMWENt", "ND4JkQj7lucz1uQO0URF3mBfQFORIzSKY2oHUPZGtJgbaDzZLY"); buildGoogleApiClient(); super.onCreate(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Required for making Facebook login work ParseFacebookUtils.onActivityResult(requestCode, resultCode, data); }