use of com.facebook.GraphRequest in project facebook-android-sdk by facebook.
the class FriendPickerFragment method createRequest.
private GraphRequest createRequest(String userID, Set<String> extraFields) {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
GraphRequest request = GraphRequest.newGraphPathRequest(accessToken, userID + friendPickerType.getRequestPath(), null);
Set<String> fields = new HashSet<String>(extraFields);
String[] requiredFields = new String[] { ID, NAME };
fields.addAll(Arrays.asList(requiredFields));
String pictureField = adapter.getPictureFieldSpecifier();
if (pictureField != null) {
fields.add(pictureField);
}
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
use of com.facebook.GraphRequest in project EC2018App by Manan-YMCA.
the class ContentActivity method onNavigationItemSelected.
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
item.setChecked(false);
drawer.closeDrawer(GravityCompat.START);
Handler handler = new Handler();
switch(id) {
case R.id.nav_home:
// handle home case
break;
case R.id.nav_profile:
handler.postDelayed(new Runnable() {
@Override
public void run() {
SharedPreferences prefs = getSharedPreferences(getResources().getString(R.string.sharedPrefName), MODE_PRIVATE);
String restoredText = prefs.getString("Phone", null);
if (restoredText == null) {
startActivity(new Intent(getApplicationContext(), RegisterActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtra("parent", "normal"));
} else {
startActivity(new Intent(getApplicationContext(), ProfileActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
}
}, 230);
break;
case R.id.nav_tickets:
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (prefs.getString("Phone", null) != null) {
startActivity(new Intent(ContentActivity.this, Tickets.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
} else {
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(ContentActivity.this);
builder.setTitle("Log In").setMessage("To view your tickets you must Log In first.").setPositiveButton("Log In", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(ContentActivity.this, LoginActivity.class).putExtra("parent", "ct"));
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
nav_view.setCheckedItem(R.id.nav_home);
dialog.dismiss();
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
dialog.dismiss();
}
}).setIcon(android.R.drawable.ic_dialog_alert).show();
}
}
}, 10);
break;
case R.id.nav_xunbao:
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(ContentActivity.this, XunbaoActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
}
}, 230);
break;
case R.id.nav_culmyca:
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(ContentActivity.this, CulmycaTimesActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
}, 230);
break;
case R.id.nav_about:
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(ContentActivity.this, AboutActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
}, 230);
break;
case R.id.nav_logout:
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case DialogInterface.BUTTON_POSITIVE:
SharedPreferences preferences = getSharedPreferences(getResources().getString(R.string.sharedPrefName), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.apply();
databaseController.deleteTickets();
FirebaseAuth.getInstance().signOut();
if (AccessToken.getCurrentAccessToken() != null) {
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
}
startActivity(new Intent(getApplicationContext(), UserLoginActivity.class).putExtra("logout", true).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
finish();
MDToast.makeText(ContentActivity.this, "Logout Successful", Toast.LENGTH_SHORT, MDToast.TYPE_SUCCESS).show();
break;
case DialogInterface.BUTTON_NEGATIVE:
// No button clicked
MDToast.makeText(ContentActivity.this, "Logout Cancelled", Toast.LENGTH_SHORT, MDToast.TYPE_INFO).show();
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(ContentActivity.this);
builder.setMessage("Do you want to logout?").setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show();
break;
case R.id.nav_sponsors:
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(ContentActivity.this, SponsorsActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
}, 230);
break;
case R.id.nav_notifications:
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(ContentActivity.this, MyNotificationsActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
}, 230);
break;
case R.id.nav_share:
String msg = "Install the elements culmyca app to stay updated about the latest events. Follow the link: ";
shareTextMessage(msg);
break;
case R.id.nav_bug:
String to = "manantechnosurge@gmail.com";
String subject = "Bug Found";
String messg = "I found a bug!\n";
sendEmailBug(to, subject, messg);
break;
case R.id.nav_dev:
// TODO
startActivity(new Intent(ContentActivity.this, DevelopersActivity.class));
// show developers
break;
case R.id.nav_location:
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(ContentActivity.this, MapsActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}
}, 230);
break;
}
return true;
}
use of com.facebook.GraphRequest in project RxFacebook by YouClap.
the class RxFacebookGraphRequestSingle method subscribeActual.
@Override
protected void subscribeActual(@NonNull SingleObserver<? super GraphResponse> observer) {
mObserver = observer;
GraphRequest request = GraphRequest.newMeRequest(mAccessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (response.getError() == null) {
mObserver.onSuccess(response);
} else {
mObserver.onError(response.getError().getException());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", mFields);
request.setParameters(parameters);
request.executeAsync();
}
use of com.facebook.GraphRequest in project Precisely by Pankaj-Baranwal.
the class SignUp method getUserProfile.
// FB Response Handling
private void getUserProfile(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (response != null && response.getError() == null) {
try {
String user_id;
if (response.getJSONObject().has("name")) {
Constants.user_name = response.getJSONObject().getString("name");
} else {
Constants.user_name = "Anonymous User";
}
if (response.getJSONObject().has("email")) {
user_id = response.getJSONObject().getString("email");
} else {
user_id = response.getJSONObject().getString("id");
}
submitData(user_id);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Toast.makeText(SignUp.this, "Couldn't submit response", Toast.LENGTH_SHORT).show();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,picture,link");
request.setParameters(parameters);
request.executeAsync();
}
use of com.facebook.GraphRequest in project androidApp by InspectorIncognito.
the class FacebookDataManager method getCredentials.
void getCredentials(final CredentialsListener listener) {
Log.d(TAG, "getUserData");
final AccessToken currentToken = AccessToken.getCurrentAccessToken();
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", null, HttpMethod.GET, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
Profile profile = Profile.getCurrentProfile();
String email = response.getJSONObject().getString("email");
String name = response.getJSONObject().getString("name");
String imageUri = profile.getProfilePictureUri(200, 200).toString();
SocialMediaCredentials credentials = new SocialMediaCredentials(currentToken.getToken(), currentToken.getUserId(), FACEBOOK_ACCOUNT, name, email, imageUri);
listener.onSuccess(new FacebookAccount(credentials));
} catch (JSONException | NullPointerException e) {
listener.onError(new ServerStatusCode(ServerStatusCode.LOGIN_API_ERROR));
Log.e(TAG, e.getMessage() == null ? "null message" : e.getMessage());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
Aggregations