private static void validate(ShareContent content, Validator validator)
throws FacebookException {
if (content == null) {
throw new FacebookException("Must provide non-null content to share");
}
if (content instanceof ShareLinkContent) {
validator.validate((ShareLinkContent) content);
} else if (content instanceof SharePhotoContent) {
validator.validate((SharePhotoContent) content);
} else if (content instanceof ShareVideoContent) {
validator.validate((ShareVideoContent) content);
} else if (content instanceof ShareOpenGraphContent) {
validator.validate((ShareOpenGraphContent) content);
}
}
java类com.facebook.FacebookException的实例源码
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 24
收藏 0
点赞 0
评论 0
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 28
收藏 0
点赞 0
评论 0
private static void validatePhotoContent(
SharePhotoContent photoContent, Validator validator) {
List<SharePhoto> photos = photoContent.getPhotos();
if (photos == null || photos.isEmpty()) {
throw new FacebookException("Must specify at least one Photo in SharePhotoContent.");
}
if (photos.size() > ShareConstants.MAXIMUM_PHOTO_COUNT) {
throw new FacebookException(
String.format(
Locale.ROOT,
"Cannot add more than %d photos.",
ShareConstants.MAXIMUM_PHOTO_COUNT));
}
for (SharePhoto photo : photos) {
validator.validate(photo);
}
}
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 27
收藏 0
点赞 0
评论 0
private static void validatePhotoForApi(SharePhoto photo, Validator validator) {
if (photo == null) {
throw new FacebookException("Cannot share a null SharePhoto");
}
Bitmap photoBitmap = photo.getBitmap();
Uri photoUri = photo.getImageUrl();
if (photoBitmap == null) {
if (photoUri == null) {
throw new FacebookException(
"SharePhoto does not have a Bitmap or ImageUrl specified");
}
if (Utility.isWebUri(photoUri) && !validator.isOpenGraphContent()) {
throw new FacebookException(
"Cannot set the ImageUrl of a SharePhoto to the Uri of an image on the " +
"web when sharing SharePhotoContent");
}
}
}
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 26
收藏 0
点赞 0
评论 0
private static void validateOpenGraphContent(
ShareOpenGraphContent openGraphContent, Validator validator) {
validator.validate(openGraphContent.getAction());
String previewPropertyName = openGraphContent.getPreviewPropertyName();
if (Utility.isNullOrEmpty(previewPropertyName)) {
throw new FacebookException("Must specify a previewPropertyName.");
}
if (openGraphContent.getAction().get(previewPropertyName) == null) {
throw new FacebookException(
"Property \"" + previewPropertyName + "\" was not found on the action. " +
"The name of the preview property must match the name of an " +
"action property.");
}
}
NativeProtocol.java 文件源码
项目:letv
阅读 26
收藏 0
点赞 0
评论 0
public static FacebookException getExceptionFromErrorData(Bundle errorData) {
if (errorData == null) {
return null;
}
String type = errorData.getString(BRIDGE_ARG_ERROR_TYPE);
if (type == null) {
type = errorData.getString(STATUS_ERROR_TYPE);
}
String description = errorData.getString(BRIDGE_ARG_ERROR_DESCRIPTION);
if (description == null) {
description = errorData.getString(STATUS_ERROR_DESCRIPTION);
}
if (type == null || !type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
return new FacebookException(description);
}
return new FacebookOperationCanceledException(description);
}
LoginActivity.java 文件源码
项目:social-journal
阅读 37
收藏 0
点赞 0
评论 0
void initializeFacebookLogin() {
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email", "public_profile", "user_posts", "user_photos");
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");
// ...
}
@Override
public void onError(FacebookException error) {
Log.w(TAG, "facebook:onError", error);
}
});
}
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 23
收藏 0
点赞 0
评论 0
private static void validateOpenGraphValueContainer(
ShareOpenGraphValueContainer valueContainer,
Validator validator,
boolean requireNamespace) {
Set<String> keySet = valueContainer.keySet();
for (String key : keySet) {
validateOpenGraphKey(key, requireNamespace);
Object o = valueContainer.get(key);
if (o instanceof List) {
List list = (List) o;
for (Object objectInList : list) {
if (objectInList == null) {
throw new FacebookException(
"Cannot put null objects in Lists in " +
"ShareOpenGraphObjects and ShareOpenGraphActions");
}
validateOpenGraphValueContainerObject(objectInList, validator);
}
} else {
validateOpenGraphValueContainerObject(o, validator);
}
}
}
ShareInternalUtility.java 文件源码
项目:kognitivo
阅读 26
收藏 0
点赞 0
评论 0
public static void registerSharerCallback(
final int requestCode,
final CallbackManager callbackManager,
final FacebookCallback<Sharer.Result> callback) {
if (!(callbackManager instanceof CallbackManagerImpl)) {
throw new FacebookException("Unexpected CallbackManager, " +
"please use the provided Factory.");
}
((CallbackManagerImpl) callbackManager).registerCallback(
requestCode,
new CallbackManagerImpl.Callback() {
@Override
public boolean onActivityResult(int resultCode, Intent data) {
return handleActivityResult(
requestCode,
resultCode,
data,
getShareResultProcessor(callback));
}
});
}
ShareInternalUtility.java 文件源码
项目:kognitivo
阅读 23
收藏 0
点赞 0
评论 0
public static JSONObject toJSONObjectForWeb(
final ShareOpenGraphContent shareOpenGraphContent)
throws JSONException {
ShareOpenGraphAction action = shareOpenGraphContent.getAction();
return OpenGraphJSONUtility.toJSONObject(
action,
new OpenGraphJSONUtility.PhotoJSONProcessor() {
@Override
public JSONObject toJSONObject(SharePhoto photo) {
Uri photoUri = photo.getImageUrl();
JSONObject photoJSONObject = new JSONObject();
try {
photoJSONObject.put(
NativeProtocol.IMAGE_URL_KEY, photoUri.toString());
} catch (JSONException e) {
throw new FacebookException("Unable to attach images", e);
}
return photoJSONObject;
}
});
}
VideoUploader.java 文件源码
项目:kognitivo
阅读 24
收藏 0
点赞 0
评论 0
private static void issueResponse(
final UploadContext uploadContext,
final FacebookException error,
final String videoId) {
// Remove the UploadContext synchronously
// Once the UploadContext is removed, this is the only reference to it.
removePendingUpload(uploadContext);
Utility.closeQuietly(uploadContext.videoStream);
if (uploadContext.callback != null) {
if (error != null) {
ShareInternalUtility.invokeOnErrorCallback(uploadContext.callback, error);
} else if (uploadContext.isCanceled) {
ShareInternalUtility.invokeOnCancelCallback(uploadContext.callback);
} else {
ShareInternalUtility.invokeOnSuccessCallback(uploadContext.callback, videoId);
}
}
}
VideoUploader.java 文件源码
项目:kognitivo
阅读 25
收藏 0
点赞 0
评论 0
private void initialize()
throws FileNotFoundException {
ParcelFileDescriptor fileDescriptor = null;
try {
if (Utility.isFileUri(videoUri)) {
fileDescriptor = ParcelFileDescriptor.open(
new File(videoUri.getPath()),
ParcelFileDescriptor.MODE_READ_ONLY);
videoSize = fileDescriptor.getStatSize();
videoStream = new ParcelFileDescriptor.AutoCloseInputStream(fileDescriptor);
} else if (Utility.isContentUri(videoUri)) {
videoSize = Utility.getContentSize(videoUri);
videoStream = FacebookSdk
.getApplicationContext()
.getContentResolver()
.openInputStream(videoUri);
} else {
throw new FacebookException("Uri must be a content:// or file:// uri");
}
} catch (FileNotFoundException e) {
Utility.closeQuietly(videoStream);
throw e;
}
}
VideoUploader.java 文件源码
项目:kognitivo
阅读 32
收藏 0
点赞 0
评论 0
@Override
public Bundle getParameters()
throws IOException {
Bundle parameters = new Bundle();
parameters.putString(PARAM_UPLOAD_PHASE, PARAM_VALUE_UPLOAD_TRANSFER_PHASE);
parameters.putString(PARAM_SESSION_ID, uploadContext.sessionId);
parameters.putString(PARAM_START_OFFSET, chunkStart);
byte[] chunk = getChunk(uploadContext, chunkStart, chunkEnd);
if (chunk != null) {
parameters.putByteArray(PARAM_VIDEO_FILE_CHUNK, chunk);
} else {
throw new FacebookException("Error reading video");
}
return parameters;
}
FacebookHelper.java 文件源码
项目:AndroidBlueprints
阅读 24
收藏 0
点赞 0
评论 0
/**
* Register call back manager to Google log in button.
*
* @param activity the activity
* @param loginButton the login button
*/
private void registerCallBackManager(final Activity activity, LoginButton loginButton) {
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
mLoginResult = loginResult;
getUserProfile(activity);
}
@Override
public void onCancel() {
mFacebookLoginResultCallBack.onFacebookLoginCancel();
}
@Override
public void onError(FacebookException error) {
mFacebookLoginResultCallBack.onFacebookLoginError(error);
}
});
}
LoginFacebook.java 文件源码
项目:enklave
阅读 24
收藏 0
点赞 0
评论 0
public LoginFacebook(LoginButton login, Activity context, PreferencesShared pref, final Intent intent) {
callbackManager = CallbackManager.Factory.create();
this.context = context;
preferencesShared = pref;
login.setReadPermissions(Arrays.asList("public_profile", "user_friends"));
login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
//Log.d("facebook", "succes" + loginResult.getAccessToken().getToken() + "id" + loginResult.getAccessToken().getExpires() + "data" + loginResult.getAccessToken().getUserId());
conectedwithFacebook(loginResult.getAccessToken().getToken(),intent);
}
@Override
public void onCancel() {
Log.d("intra","facebook");
}
@Override
public void onError(FacebookException error) {
Log.d("facebook", "error" + error.toString());
}
});
}
LoginClient.java 文件源码
项目:kognitivo
阅读 39
收藏 0
点赞 0
评论 0
void authorize(Request request) {
if (request == null) {
return;
}
if (pendingRequest != null) {
throw new FacebookException("Attempted to authorize while a request is pending.");
}
if (AccessToken.getCurrentAccessToken() != null && !checkInternetPermission()) {
// We're going to need INTERNET permission later and don't have it, so fail early.
return;
}
pendingRequest = request;
handlersToTry = getHandlersToTry(request);
tryNextHandler();
}
ProfilePictureView.java 文件源码
项目:kognitivo
阅读 30
收藏 0
点赞 0
评论 0
private void processResponse(ImageResponse response) {
// First check if the response is for the right request. We may have:
// 1. Sent a new request, thus super-ceding this one.
// 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);
}
}
}
}
RegistrationPresenterImpl.java 文件源码
项目:BizareChat
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void setCallbackToLoginFacebookButton() {
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Bundle param = new Bundle();
param.putString("fields", "id, email");
facebookLink(loginResult);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
Logger.logExceptionToFabric(error);
}
});
}
NativeProtocol.java 文件源码
项目:kognitivo
阅读 28
收藏 0
点赞 0
评论 0
public static FacebookException getExceptionFromErrorData(Bundle errorData) {
if (errorData == null) {
return null;
}
String type = errorData.getString(BRIDGE_ARG_ERROR_TYPE);
if (type == null) {
type = errorData.getString(STATUS_ERROR_TYPE);
}
String description = errorData.getString(BRIDGE_ARG_ERROR_DESCRIPTION);
if (description == null) {
description = errorData.getString(STATUS_ERROR_DESCRIPTION);
}
if (type != null && type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
return new FacebookOperationCanceledException(description);
}
/* TODO parse error values and create appropriate exception class */
return new FacebookException(description);
}
ProfilePictureView.java 文件源码
项目:AndroidBackendlessChat
阅读 31
收藏 0
点赞 0
评论 0
private void processResponse(ImageResponse response) {
// First check if the response is for the right request. We may have:
// 1. Sent a new request, thus super-ceding this one.
// 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);
}
}
}
}
FacebookHelper.java 文件源码
项目:social-login-helper
阅读 29
收藏 0
点赞 0
评论 0
public FacebookHelper(@NonNull FacebookListener facebookListener) {
mListener = facebookListener;
mCallBackManager = CallbackManager.Factory.create();
FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
@Override public void onSuccess(LoginResult loginResult) {
mListener.onFbSignInSuccess(loginResult.getAccessToken().getToken(),
loginResult.getAccessToken().getUserId());
}
@Override public void onCancel() {
mListener.onFbSignInFail("User cancelled operation");
}
@Override public void onError(FacebookException e) {
mListener.onFbSignInFail(e.getMessage());
}
};
LoginManager.getInstance().registerCallback(mCallBackManager, mCallBack);
}
LoginActivity.java 文件源码
项目:android-paypal-example
阅读 31
收藏 0
点赞 0
评论 0
@OnClick(R.id.fb_login)
public void setUpFacebookLoginButton() {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "public_profile"));
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
if(!isNetworkConnected()){
Snackbar.make(findViewById(android.R.id.content),"please check internet connection"
,Snackbar.LENGTH_SHORT).show();
}else{
Snackbar.make(findViewById(android.R.id.content),"unexpected error,please try again later"
,Snackbar.LENGTH_SHORT).show();
}
}
});
}
AuthenticateFragment.java 文件源码
项目:Stalker
阅读 24
收藏 0
点赞 0
评论 0
protected void registerFacebookCallback() {
LoginManager.getInstance().registerCallback(facebookCallbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.d(TAG, "Login Success");
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
// App code
Log.d(TAG, "Login canceled");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.d(TAG, "Login error");
}
});
}
ProfilePictureView.java 文件源码
项目:chat-sdk-android-push-firebase
阅读 30
收藏 0
点赞 0
评论 0
private void processResponse(ImageResponse response) {
// First check if the response is for the right request. We may have:
// 1. Sent a new request, thus super-ceding this one.
// 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);
}
}
}
}
SignIn.java 文件源码
项目:AddyHINT17
阅读 38
收藏 0
点赞 0
评论 0
private void facebookLogIn(View view) {
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
// If using in a fragment
loginButton.setFragment(this);
// Other app specific specialization
loginButton.performClick();
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Toast.makeText(getContext(), "Logged In Successfully", Toast.LENGTH_SHORT).show();
setSessionManagement();
startActivity(new Intent(getApplicationContext(), MapsActivity.class));
}
@Override
public void onCancel() {
// App code
Toast.makeText(getContext(), "LogIn Failed",
Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException exception) {
// App code
Toast.makeText(getContext(), "LogIn Failed",
Toast.LENGTH_SHORT).show();
}
});
}
NativeDialogParameters.java 文件源码
项目:kognitivo
阅读 23
收藏 0
点赞 0
评论 0
public static Bundle create(
UUID callId,
ShareContent shareContent,
boolean shouldFailOnDataError) {
Validate.notNull(shareContent, "shareContent");
Validate.notNull(callId, "callId");
Bundle nativeParams = null;
if (shareContent instanceof ShareLinkContent) {
final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
nativeParams = create(linkContent, shouldFailOnDataError);
} else if (shareContent instanceof SharePhotoContent) {
final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
List<String> photoUrls = ShareInternalUtility.getPhotoUrls(
photoContent,
callId);
nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
} else if (shareContent instanceof ShareVideoContent) {
final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId);
nativeParams = create(videoContent, videoUrl, shouldFailOnDataError);
} else if (shareContent instanceof ShareOpenGraphContent) {
final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
try {
JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(
callId, openGraphContent);
openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(
openGraphActionJSON, false);
nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
} catch (final JSONException e) {
throw new FacebookException(
"Unable to create a JSON Object from the provided ShareOpenGraphContent: "
+ e.getMessage());
}
}
return nativeParams;
}
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 25
收藏 0
点赞 0
评论 0
private static void validateLinkContent(
ShareLinkContent linkContent, Validator validator) {
Uri imageUrl = linkContent.getImageUrl();
if (imageUrl != null && !Utility.isWebUri(imageUrl)) {
throw new FacebookException("Image Url must be an http:// or https:// url");
}
}
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 27
收藏 0
点赞 0
评论 0
private static void validatePhotoForWebDialog(SharePhoto photo, Validator validator) {
if (photo == null) {
throw new FacebookException("Cannot share a null SharePhoto");
}
Uri imageUri = photo.getImageUrl();
if (imageUri == null || !Utility.isWebUri(imageUri)) {
throw new FacebookException(
"SharePhoto must have a non-null imageUrl set to the Uri of an image " +
"on the web");
}
}
ShareContentValidation.java 文件源码
项目:kognitivo
阅读 27
收藏 0
点赞 0
评论 0
private static void validateVideo(ShareVideo video, Validator validator) {
if (video == null) {
throw new FacebookException("Cannot share a null ShareVideo");
}
Uri localUri = video.getLocalUrl();
if (localUri == null) {
throw new FacebookException("ShareVideo does not have a LocalUrl specified");
}
if (!Utility.isContentUri(localUri) && !Utility.isFileUri(localUri)) {
throw new FacebookException("ShareVideo must reference a video that is on the device");
}
}
ShareInternalUtility.java 文件源码
项目:kognitivo
阅读 27
收藏 0
点赞 0
评论 0
public static void invokeCallbackWithException(
FacebookCallback<Sharer.Result> callback,
final Exception exception) {
if (exception instanceof FacebookException) {
invokeOnErrorCallback(callback, (FacebookException) exception);
return;
}
invokeCallbackWithError(
callback,
"Error preparing share content: " + exception.getLocalizedMessage());
}
ShareInternalUtility.java 文件源码
项目:kognitivo
阅读 25
收藏 0
点赞 0
评论 0
public static boolean handleActivityResult(
int requestCode,
int resultCode,
Intent data,
ResultProcessor resultProcessor) {
AppCall appCall = getAppCallFromActivityResult(requestCode, resultCode, data);
if (appCall == null) {
return false;
}
NativeAppCallAttachmentStore.cleanupAttachmentsForCall(appCall.getCallId());
if (resultProcessor == null) {
return true;
}
FacebookException exception = NativeProtocol.getExceptionFromErrorData(
NativeProtocol.getErrorDataFromResultIntent(data));
if (exception != null) {
if (exception instanceof FacebookOperationCanceledException) {
resultProcessor.onCancel(appCall);
} else {
resultProcessor.onError(appCall, exception);
}
} else {
// If here, we did not find an error in the result.
Bundle results = NativeProtocol.getSuccessResultsFromIntent(data);
resultProcessor.onSuccess(appCall, results);
}
return true;
}