use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class FacebookLoginActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook_login);
callbackManager = CallbackManager.Factory.create();
fbLoginButton = (LoginButton) findViewById(R.id._fb_login);
profilePictureView = (ProfilePictureView) findViewById(R.id.user_pic);
profilePictureView.setCropped(true);
userNameView = (TextView) findViewById(R.id.user_name);
final Button deAuthButton = (Button) findViewById(R.id.deauth);
deAuthButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!isLoggedIn()) {
Toast.makeText(FacebookLoginActivity.this, R.string.app_not_logged_in, Toast.LENGTH_LONG).show();
return;
}
GraphRequest.Callback callback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
try {
if (response.getError() != null) {
Toast.makeText(FacebookLoginActivity.this, getResources().getString(R.string.failed_to_deauth, response.toString()), Toast.LENGTH_LONG).show();
} else if (response.getJSONObject().getBoolean(SUCCESS)) {
LoginManager.getInstance().logOut();
// updateUI();?
}
} catch (JSONException ex) {
/* no op */
}
}
};
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), GRAPH_PATH, new Bundle(), HttpMethod.DELETE, callback);
request.executeAsync();
}
});
final Button permsButton = (Button) findViewById(R.id.perms);
permsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(final View v) {
Intent selectPermsIntent = new Intent(FacebookLoginActivity.this, PermissionSelectActivity.class);
startActivityForResult(selectPermsIntent, PICK_PERMS_REQUEST);
}
});
// Callback registration
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(final LoginResult loginResult) {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.success, Toast.LENGTH_LONG).show();
updateUI();
}
@Override
public void onCancel() {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.cancel, Toast.LENGTH_LONG).show();
}
@Override
public void onError(final FacebookException exception) {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.error, Toast.LENGTH_LONG).show();
}
});
new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(final Profile oldProfile, final Profile currentProfile) {
updateUI();
}
};
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class PickerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pickers);
Bundle args = getIntent().getExtras();
FragmentManager manager = getFragmentManager();
Fragment fragmentToShow = null;
Uri intentUri = getIntent().getData();
if (FRIEND_PICKER.equals(intentUri)) {
if (savedInstanceState == null) {
friendPickerFragment = new FriendPickerFragment();
friendPickerFragment.setSettingsFromBundle(args);
friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS);
} else {
friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
;
}
friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
@Override
public void onError(PickerFragment fragment, FacebookException error) {
PickerActivity.this.onError(error);
}
});
friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
@Override
public void onDoneButtonClicked(PickerFragment fragment) {
finishActivity();
}
});
fragmentToShow = friendPickerFragment;
} else if (PLACE_PICKER.equals(intentUri)) {
if (savedInstanceState == null) {
placePickerFragment = new PlacePickerFragment();
placePickerFragment.setSettingsFromBundle(args);
} else {
placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
}
placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
@Override
public void onSelectionChanged(PickerFragment fragment) {
// call finish since you can only pick one place
finishActivity();
}
});
placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
@Override
public void onError(PickerFragment fragment, FacebookException error) {
PickerActivity.this.onError(error);
}
});
placePickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
@Override
public void onDoneButtonClicked(PickerFragment fragment) {
finishActivity();
}
});
fragmentToShow = placePickerFragment;
} else {
// Nothing to do, finish
setResult(RESULT_CANCELED);
finish();
return;
}
manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AppEventsLogger method updateUserProperties.
public static void updateUserProperties(final Bundle parameters, final String applicationID, final GraphRequest.Callback callback) {
final String userID = getUserID();
if (userID == null || userID.isEmpty()) {
Logger.log(LoggingBehavior.APP_EVENTS, TAG, "AppEventsLogger userID cannot be null or empty");
return;
}
getAnalyticsExecutor().execute(new Runnable() {
@Override
public void run() {
Bundle userPropertiesParams = new Bundle();
userPropertiesParams.putString("user_unique_id", userID);
userPropertiesParams.putBundle("custom_data", parameters);
// This call must be run on the background thread
AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(FacebookSdk.getApplicationContext());
if (identifiers != null && identifiers.getAndroidAdvertiserId() != null) {
userPropertiesParams.putString("advertiser_id", identifiers.getAndroidAdvertiserId());
}
Bundle data = new Bundle();
try {
JSONObject userData = BundleJSONConverter.convertToJSON(userPropertiesParams);
JSONArray dataArray = new JSONArray();
dataArray.put(userData);
data.putString("data", dataArray.toString());
} catch (JSONException ex) {
throw new FacebookException("Failed to construct request", ex);
}
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), String.format(Locale.US, "%s/user_properties", applicationID), data, HttpMethod.POST, callback);
request.setSkipClientToken(true);
request.executeAsync();
}
});
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AttributionIdentifiers method getAndroidIdViaReflection.
private static AttributionIdentifiers getAndroidIdViaReflection(Context context) {
try {
// freeze, if this is the case throw:
if (Looper.myLooper() == Looper.getMainLooper()) {
throw new FacebookException("getAndroidId cannot be called on the main thread.");
}
Method isGooglePlayServicesAvailable = Utility.getMethodQuietly("com.google.android.gms.common.GooglePlayServicesUtil", "isGooglePlayServicesAvailable", Context.class);
if (isGooglePlayServicesAvailable == null) {
return null;
}
Object connectionResult = Utility.invokeMethodQuietly(null, isGooglePlayServicesAvailable, context);
if (!(connectionResult instanceof Integer) || (Integer) connectionResult != CONNECTION_RESULT_SUCCESS) {
return null;
}
Method getAdvertisingIdInfo = Utility.getMethodQuietly("com.google.android.gms.ads.identifier.AdvertisingIdClient", "getAdvertisingIdInfo", Context.class);
if (getAdvertisingIdInfo == null) {
return null;
}
Object advertisingInfo = Utility.invokeMethodQuietly(null, getAdvertisingIdInfo, context);
if (advertisingInfo == null) {
return null;
}
Method getId = Utility.getMethodQuietly(advertisingInfo.getClass(), "getId");
Method isLimitAdTrackingEnabled = Utility.getMethodQuietly(advertisingInfo.getClass(), "isLimitAdTrackingEnabled");
if (getId == null || isLimitAdTrackingEnabled == null) {
return null;
}
AttributionIdentifiers identifiers = new AttributionIdentifiers();
identifiers.androidAdvertiserId = (String) Utility.invokeMethodQuietly(advertisingInfo, getId);
identifiers.limitTracking = (Boolean) Utility.invokeMethodQuietly(advertisingInfo, isLimitAdTrackingEnabled);
return identifiers;
} catch (Exception e) {
Utility.logd("android_id", e);
}
return null;
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class AppLinkData method createFromJson.
private static AppLinkData createFromJson(String jsonString) {
if (jsonString == null) {
return null;
}
try {
// Any missing or malformed data will result in a JSONException
JSONObject appLinkArgsJson = new JSONObject(jsonString);
String version = appLinkArgsJson.getString(APPLINK_VERSION_KEY);
JSONObject bridgeArgs = appLinkArgsJson.getJSONObject(APPLINK_BRIDGE_ARGS_KEY);
String method = bridgeArgs.getString(BRIDGE_ARGS_METHOD_KEY);
if (method.equals("applink") && version.equals("2")) {
// We have a new deep link
AppLinkData appLinkData = new AppLinkData();
appLinkData.arguments = appLinkArgsJson.getJSONObject(APPLINK_METHOD_ARGS_KEY);
// first look for the "ref" key in the top level args
if (appLinkData.arguments.has(METHOD_ARGS_REF_KEY)) {
appLinkData.ref = appLinkData.arguments.getString(METHOD_ARGS_REF_KEY);
} else if (appLinkData.arguments.has(ARGUMENTS_REFERER_DATA_KEY)) {
// if it's not in the top level args, it could be in the "referer_data" blob
JSONObject refererData = appLinkData.arguments.getJSONObject(ARGUMENTS_REFERER_DATA_KEY);
if (refererData.has(REFERER_DATA_REF_KEY)) {
appLinkData.ref = refererData.getString(REFERER_DATA_REF_KEY);
}
}
if (appLinkData.arguments.has(METHOD_ARGS_TARGET_URL_KEY)) {
appLinkData.targetUri = Uri.parse(appLinkData.arguments.getString(METHOD_ARGS_TARGET_URL_KEY));
}
if (appLinkData.arguments.has(ARGUMENTS_EXTRAS_KEY)) {
JSONObject extrasData = appLinkData.arguments.getJSONObject(ARGUMENTS_EXTRAS_KEY);
if (extrasData.has(EXTRAS_DEEPLINK_CONTEXT_KEY)) {
JSONObject deeplink_context = extrasData.getJSONObject(EXTRAS_DEEPLINK_CONTEXT_KEY);
if (deeplink_context.has(PROMOTION_CODE_KEY)) {
appLinkData.promotionCode = deeplink_context.getString(PROMOTION_CODE_KEY);
}
}
}
appLinkData.argumentBundle = toBundle(appLinkData.arguments);
return appLinkData;
}
} catch (JSONException e) {
Log.d(TAG, "Unable to parse AppLink JSON", e);
} catch (FacebookException e) {
Log.d(TAG, "Unable to parse AppLink JSON", e);
}
return null;
}
Aggregations