use of com.facebook.FacebookException in project facebook-api-android-maven by avianey.
the class AttributionIdentifiers method getAndroidId.
private static AttributionIdentifiers getAndroidId(Context context) {
AttributionIdentifiers identifiers = new AttributionIdentifiers();
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 identifiers;
}
Object connectionResult = Utility.invokeMethodQuietly(null, isGooglePlayServicesAvailable, context);
if (!(connectionResult instanceof Integer) || (Integer) connectionResult != CONNECTION_RESULT_SUCCESS) {
return identifiers;
}
Method getAdvertisingIdInfo = Utility.getMethodQuietly("com.google.android.gms.ads.identifier.AdvertisingIdClient", "getAdvertisingIdInfo", Context.class);
if (getAdvertisingIdInfo == null) {
return identifiers;
}
Object advertisingInfo = Utility.invokeMethodQuietly(null, getAdvertisingIdInfo, context);
if (advertisingInfo == null) {
return identifiers;
}
Method getId = Utility.getMethodQuietly(advertisingInfo.getClass(), "getId");
Method isLimitAdTrackingEnabled = Utility.getMethodQuietly(advertisingInfo.getClass(), "isLimitAdTrackingEnabled");
if (getId == null || isLimitAdTrackingEnabled == null) {
return identifiers;
}
identifiers.androidAdvertiserId = (String) Utility.invokeMethodQuietly(advertisingInfo, getId);
identifiers.limitTracking = (Boolean) Utility.invokeMethodQuietly(advertisingInfo, isLimitAdTrackingEnabled);
} catch (Exception e) {
Utility.logd("android_id", e);
}
return identifiers;
}
use of com.facebook.FacebookException in project facebook-api-android-maven by avianey.
the class ImageDownloader method download.
private static void download(RequestKey key, Context context) {
HttpURLConnection connection = null;
InputStream stream = null;
Exception error = null;
Bitmap bitmap = null;
boolean issueResponse = true;
try {
URL url = new URL(key.uri.toString());
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
switch(connection.getResponseCode()) {
case HttpURLConnection.HTTP_MOVED_PERM:
case HttpURLConnection.HTTP_MOVED_TEMP:
// redirect. So we need to perform further requests
issueResponse = false;
String redirectLocation = connection.getHeaderField("location");
if (!Utility.isNullOrEmpty(redirectLocation)) {
URI redirectUri = new URI(redirectLocation);
UrlRedirectCache.cacheUriRedirect(context, key.uri, redirectUri);
// Once the old downloader context is removed, we are thread-safe since this is the
// only reference to it
DownloaderContext downloaderContext = removePendingRequest(key);
if (downloaderContext != null && !downloaderContext.isCancelled) {
enqueueCacheRead(downloaderContext.request, new RequestKey(redirectUri, key.tag), false);
}
}
break;
case HttpURLConnection.HTTP_OK:
// image should be available
stream = ImageResponseCache.interceptAndCacheImageStream(context, connection);
bitmap = BitmapFactory.decodeStream(stream);
break;
default:
stream = connection.getErrorStream();
InputStreamReader reader = new InputStreamReader(stream);
char[] buffer = new char[128];
int bufferLength;
StringBuilder errorMessageBuilder = new StringBuilder();
while ((bufferLength = reader.read(buffer, 0, buffer.length)) > 0) {
errorMessageBuilder.append(buffer, 0, bufferLength);
}
Utility.closeQuietly(reader);
error = new FacebookException(errorMessageBuilder.toString());
break;
}
} catch (IOException e) {
error = e;
} catch (URISyntaxException e) {
error = e;
} finally {
Utility.closeQuietly(stream);
Utility.disconnectQuietly(connection);
}
if (issueResponse) {
issueResponse(key, error, bitmap, false);
}
}
use of com.facebook.FacebookException in project facebook-api-android-maven by avianey.
the class ProfilePictureView method processResponse.
private void processResponse(ImageResponse response) {
// 2. Detached this view, in which case the response should be discarded.
if (response.getRequest() == lastRequest) {
lastRequest = null;
Bitmap responseImage = response.getBitmap();
Exception error = response.getError();
if (error != null) {
OnErrorListener listener = onErrorListener;
if (listener != null) {
listener.onError(new FacebookException("Error in downloading profile picture for profileId: " + getProfileId(), error));
} else {
Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, error.toString());
}
} else if (responseImage != null) {
setImageBitmap(responseImage);
if (response.isCachedRedirect()) {
sendImageRequest(false);
}
}
}
}
use of com.facebook.FacebookException in project quickstart-android by firebase.
the class FacebookLoginActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_facebook);
// Views
mStatusTextView = (TextView) findViewById(R.id.status);
mDetailTextView = (TextView) findViewById(R.id.detail);
findViewById(R.id.button_facebook_signout).setOnClickListener(this);
// [START initialize_auth]
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
// [END initialize_auth]
// [START auth_state_listener]
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// [START_EXCLUDE]
updateUI(user);
// [END_EXCLUDE]
}
};
// [END auth_state_listener]
// [START initialize_fblogin]
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
// [START_EXCLUDE]
updateUI(null);
// [END_EXCLUDE]
}
});
// [END initialize_fblogin]
}
use of com.facebook.FacebookException in project facebook-android-sdk by facebook.
the class ShareApi method stagePhoto.
private void stagePhoto(final SharePhoto photo, final CollectionMapper.OnMapValueCompleteListener onPhotoStagedListener) {
final Bitmap bitmap = photo.getBitmap();
final Uri imageUrl = photo.getImageUrl();
if ((bitmap != null) || (imageUrl != null)) {
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final FacebookRequestError error = response.getError();
if (error != null) {
String message = error.getErrorMessage();
if (message == null) {
message = "Error staging photo.";
}
onPhotoStagedListener.onError(new FacebookGraphResponseException(response, message));
return;
}
final JSONObject data = response.getJSONObject();
if (data == null) {
onPhotoStagedListener.onError(new FacebookException("Error staging photo."));
return;
}
final String stagedImageUri = data.optString("uri");
if (stagedImageUri == null) {
onPhotoStagedListener.onError(new FacebookException("Error staging photo."));
return;
}
final JSONObject stagedObject = new JSONObject();
try {
stagedObject.put("url", stagedImageUri);
stagedObject.put("user_generated", photo.getUserGenerated());
} catch (final JSONException ex) {
String message = ex.getLocalizedMessage();
if (message == null) {
message = "Error staging photo.";
}
onPhotoStagedListener.onError(new FacebookException(message));
return;
}
onPhotoStagedListener.onComplete(stagedObject);
}
};
if (bitmap != null) {
ShareInternalUtility.newUploadStagingResourceWithImageRequest(AccessToken.getCurrentAccessToken(), bitmap, requestCallback).executeAsync();
} else {
try {
ShareInternalUtility.newUploadStagingResourceWithImageRequest(AccessToken.getCurrentAccessToken(), imageUrl, requestCallback).executeAsync();
} catch (final FileNotFoundException ex) {
String message = ex.getLocalizedMessage();
if (message == null) {
message = "Error staging photo.";
}
onPhotoStagedListener.onError(new FacebookException(message));
}
}
} else {
onPhotoStagedListener.onError(new FacebookException("Photos must have an imageURL or bitmap."));
}
}
Aggregations