2016-03-08 125 views
1

如何在Android上分享張貼在牆上從Facebook的SDK 4.10.0?發佈在Facebook牆上與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"); 
 
    } 
 
});

我正在使用此代碼...

回答

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) {} 
 
});

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); 
 
       }