I have a solution that can help you, I use this for my code and its performance.
private void publishFeedDialog (String friend_uid) {
try{ Session mCurrentSession = Session.getActiveSession(); SessionTracker mSessionTracker = new SessionTracker( getBaseContext(), new StatusCallback() { public void call(Session session, SessionState state, Exception exception) { } }, null, false); String applicationId = Utility .getMetadataApplicationId(getBaseContext()); mCurrentSession = mSessionTracker.getSession(); if (mCurrentSession == null || mCurrentSession.getState().isClosed()) { mSessionTracker.setSession(null); Session session = new Session.Builder(getBaseContext()) .setApplicationId(applicationId).build(); Session.setActiveSession(session); mCurrentSession = session; } if (!mCurrentSession.isOpened()) { Session.OpenRequest openRequest = null; openRequest = new Session.OpenRequest( NewFriendList.this); if (openRequest != null) { openRequest .setDefaultAudience(SessionDefaultAudience.FRIENDS); openRequest.setPermissions(Arrays.asList("email", "publish_actions")); openRequest .setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO); mCurrentSession.openForPublish(openRequest); } } if (regobj != null && friend_uid != null ) { final Activity activity = this; Bundle params = new Bundle(); //This is what you need to post to a friend wall params.putString("from", "" + regobj.MyFBID); params.putString("to", friend_uid); //up to this params.putString("name", "Facebook SDK for Android"); params.putString("caption", "Build great social apps and get more installs."); params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); params.putString("link", "https://developers.facebook.com/android"); params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, mCurrentSession, params)) .setOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(Bundle values, FacebookException error) { if (error == null) { // When the story is posted, echo the success // and the post Id. final String postId = values.getString("post_id"); if (postId != null) { Toast.makeText(activity, "Posted story, id: "+postId, Toast.LENGTH_SHORT).show(); } else { // User clicked the Cancel button Toast.makeText(activity, "Publish cancelled", Toast.LENGTH_SHORT).show(); } } else if (error instanceof FacebookOperationCanceledException) { // User clicked the "x" button Toast.makeText(activity, "Publish cancelled", Toast.LENGTH_SHORT).show(); } else { // Generic, ex: network error Toast.makeText(activity, "Error posting story", Toast.LENGTH_SHORT).show(); } } }).build(); feedDialog.show(); } }catch(Exception e) { Log.d("Error", ""+e.toString()); } }
This code will only work for one user, if you want to send it to multiple users, then you can use RequestsDialogBuilder instead of WebDialog.
source share