如何在facebook sdk 4.10.0的android中分享帖子?
List<String> permissionNeeds = Arrays.asList("publish_actions");
manager = LoginManager.getInstance();
manager.logInWithPublishPermissions(this, permissionNeeds);
manager.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
}
@Override
public void onCancel() {
System.out.println("onCancel");
}
@Override
public void onError(FacebookException exception) {
System.out.println("onError");
}
});
&#13;
我正在使用此代码......
答案 0 :(得分:1)
使用此代码。
shareDialog = new ShareDialog(this);
callbackManager = CallbackManager.Factory.create();
shareDialog.registerCallback(callbackManager, new
FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(),"Not Success",Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {}
});
&#13;
if (ShareDialog.canShow(ShareLinkContent.class)) {
//Post Link with Detail On Wall....
/* ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription("The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();*/
//Post Image on Wall...........
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.naturals1);
SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
shareDialog.show(content);
}
&#13;