4

I'm using facebook SDK for share text and image in Android.I have used following code and its working for share text but how to share image together.I'm so confused about this.If any know please suggest me.

Code:

public class MainActivity extends Activity {

Facebook facebook = new Facebook("App ID");
EditText edittext;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    edittext = (EditText) findViewById(R.id.revieew);

    facebook.authorize(this, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
        }

        @Override
        public void onFacebookError(FacebookError error) {
        }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onCancel() {
        }
    });
}

public void share(View v) {
    //facebook.dialog(this, "feed", new PostDialogListener());

    Bundle parameters = new Bundle();
    // parameters.putString("message", category_item_name_desc.getText()
    // .toString());
    // parameters.putString("picture", categoryItemsModel.getImageUrl());
    parameters.putString("caption", edittext.getText().toString());
    try {
        facebook.request("/me/feed", parameters, "POST");
        System.out
                .println("**********************POST**********************************");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}

} And also i don't want to show dialog for share image and text i want to use Edittext and button for that...

dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
Dilip
  • 2,271
  • 5
  • 32
  • 52
  • possible duplicate of [Android - Upload photo to Facebook with Facebook Android SDK](http://stackoverflow.com/questions/3109283/android-upload-photo-to-facebook-with-facebook-android-sdk) – Adil Soomro Jul 16 '12 at 12:24
  • you have url of the `image` ? – Mohsin Naeem Jul 16 '12 at 12:26
  • @AdilSoomro I have already seen this but i want to post text and image together i mean image will come from variable and on clicking on share button edittext and button should appear,we comment in edittext and when we click on share button then both image and text should share – Dilip Jul 16 '12 at 12:36

1 Answers1

2

Hey this code might be helpful,

Bundle parameters = new Bundle();
                parameters.putString("message", category_item_name_desc.getText().toString());
                parameters.putString("picture", categoryItemsModel.getImageUrl());
                parameters.putString("caption", txtDescription_desc.getText().toString());
                facebook.request("/me/feed", parameters, "POST");

You can add text by adding paramater as "caption"

user
  • 323
  • 6
  • 11
  • Thanks for suggest, But this is not working......and also not throwing any error....... – Dilip Jul 16 '12 at 12:52
  • 2
    there are few changes in facebook SDK i have implemented it so might this be the reason am getting it ... here is the link for facebook SDK changes https://github.com/johnmph/facebook-android-sdk/commit/d0e6ca9d3ecfbe964e72803fdd340cfeafa6ee2e – user Jul 17 '12 at 05:46
  • 1
    Aug 2015:: Facebook SDK has changed since this answer.. The 'picture' and 'caption' edges are no longer existent on the '/me/feed' graph. https://developers.facebook.com/docs/graph-api/reference/v2.4/user/feed – Jeremy C. Aug 12 '15 at 19:52