我想在facebook上分享一张本地图片,我的facebook sdk是4.4.1。我的代码是:
private void shareContentToFacebook(){
SharePhoto sharePhoto = new SharePhoto.Builder()
.setBitmap(mBitmap)
.build();
ArrayList<SharePhoto> photos = new ArrayList<>();
photos.add(sharePhoto);
SharePhotoContent sharePhotoContent =
new SharePhotoContent.Builder().setPhotos(photos)
.build();
if (mShareDialog.canShow(SharePhotoContent.class)) {
mShareDialog.show(sharePhotoContent);
} else if (hasPublishPermission()){
ShareApi.share(sharePhotoContent, null);
} else {
LoginManager.getInstance().logInWithPublishPermissions(PhotoPreviewFragment.this,
Arrays.asList("publish_actions"));
}
}
如果我已经安装了Facebook应用程序,它可以很好地与
一起使用mShareDialog.show(sharePhotoContent);
如果没有,它将登录代码:
LoginManager.getInstance().logInWithPublishPermissions(PhotoPreviewFragment.this,
Arrays.asList("publish_actions"));
登录成功后,我将再次传输方法shareContentToFacebook:
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
shareContentToFacebook();
Log.d("XXX", "LoginSuccess!");
}
@Override
public void onCancel() {
AccessToken.setCurrentAccessToken(null);
Log.d("XXX", "onCancel!");
}
@Override
public void onError(FacebookException e) {
AccessToken.setCurrentAccessToken(null);
Log.d("XXX","facebook error:"+e.getMessage());
}
});
但是我无法获得public_actions的权限,所以我无法进入
ShareApi.share(sharePhotoContent, null);
如果没有facebook app install和public_actions,你有没有解决方案来分享照片?