user2724022
user2724022

Reputation: 1

how to post image in facebook wall with dialog

I am using Facebook SDK and calling WebDialog in my app to post something on Facebook , it can post Text but image not,is it can't use params.putByteArray to do?

How can I resolve this problem with webDialog?

Bundle params = new Bundle();
params.putByteArray("picture",  baos.toByteArray());

WebDialog feedDialog = (
    new WebDialog.FeedDialogBuilder(CameraActivity.this,
        mData.sFB,
        params))
    .setOnCompleteListener(new OnCompleteListener(){
        @Override
        public void onComplete(Bundle values,FacebookException error) {
        })
        .build();                   
feedDialog.show();

Upvotes: 0

Views: 975

Answers (2)

Sahil Mittal
Sahil Mittal

Reputation: 20753

Alone picture wont work, you have to give some link also. Its logical right?

While posting a feed if you want to add a picture there must be some link and desc/caption (optional) associated with it. Since the picture in a feed is associated to the link that you share. Here's how a feed looks like-

If you alone want to post a photo- that's not a feed; you should use the /photos API instead and publish a photo.

So add the picture and link to the parameters, else change the API.

Upvotes: 0

Pratik Dasa
Pratik Dasa

Reputation: 7439

You can use Simple facebook for this, its very easy to use. Posting full class for your reference, just refer it and check.

 package com.core;

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Window;
    import android.widget.Toast;

    import com.minoritybiz.BaseActivity;
    import com.minoritybiz.R;
    import com.minoritybiz.data.ConstantData;
    import com.minoritybiz.facebook.entities.Feed;
    import com.minoritybiz.facebooks.Permissions;
    import com.minoritybiz.facebooks.SimpleFacebook;
    import com.minoritybiz.facebooks.SimpleFacebookConfiguration;

    public class FacebookShareActivity extends BaseActivity {

        private SimpleFacebook simpleFacebook;
        private SimpleFacebookConfiguration.Builder simpleFacebookConfigurationBuilder;
        private SimpleFacebookConfiguration simpleFacebookConfiguration;

        private String IN_MESSAGE;
        private String IN_CAPTION;
        private String IN_NAME;
        private String IN_PICTURE;
        private String IN_LINK;
        private String IN_DESCRIPTION;

        private String shareLabel = "Download our mobile app on ITunes or Google Play";

        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);

            setContentView(R.layout.ij_facebook_share);

            simpleFacebook = SimpleFacebook.getInstance(this);
            simpleFacebookConfigurationBuilder = new SimpleFacebookConfiguration.Builder();
            simpleFacebookConfigurationBuilder.setAppId(ConstantData.facebook_app_id);
            simpleFacebookConfigurationBuilder.setPermissions(new Permissions[] { Permissions.PUBLISH_ACTION, Permissions.PUBLISH_STREAM });
            simpleFacebookConfiguration = simpleFacebookConfigurationBuilder.build();
            SimpleFacebook.setConfiguration(simpleFacebookConfiguration);
            getIntentData();
            if (simpleFacebook.isLogin()) {
                publishFeed();
            } else {
                simpleFacebook.login(new OnLoginListener());
            }
        }

        private void getIntentData() {

            try {
                IN_NAME = this.getIntent().getStringExtra("NAME");
                IN_DESCRIPTION = this.getIntent().getStringExtra("DESCRIPTION");
                IN_LINK = this.getIntent().getStringExtra("LINK");
                IN_PICTURE = this.getIntent().getStringExtra("THUMB");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            simpleFacebook.onActivityResult(this, requestCode, resultCode, data);
            super.onActivityResult(requestCode, resultCode, data);
        }

        private void publishFeed() {
            final Feed feed = new Feed.Builder().setName(IN_NAME).setDescription(IN_DESCRIPTION).setPicture(IN_PICTURE).setMessage(ConstantData.eventCatName).setLink(IN_LINK)
                    .setMessage(shareLabel).build();
            simpleFacebook.publish(feed, new onPublishListener());
        }

        class OnLoginListener implements SimpleFacebook.OnLoginListener {

            @Override
            public void onLogin() {
                publishFeed();
            }

            @Override
            public void onNotAcceptingPermissions() {
            }

            @Override
            public void onThinking() {
            }

            @Override
            public void onException(Throwable throwable) {
            }

            @Override
            public void onFail(String reason) {
                Toast.makeText(FacebookShareActivity.this, "Failure", Toast.LENGTH_LONG).show();
            }
        }

        class onPublishListener implements SimpleFacebook.OnPublishListener {

            @Override
            public void onComplete(String id) {
                hideProgressDialog();
                Toast.makeText(FacebookShareActivity.this, "Posted Successfully...", Toast.LENGTH_LONG).show();
                finish();
            }

            @Override
            public void onThinking() {
                // showProgressDialog("Doing Facebook Sharing...",FacebookShareActivity.this,true);
                showProgressDialog();
            }

            @Override
            public void onException(Throwable throwable) {
                hideProgressDialog();
                throwable.printStackTrace();
            }

            @Override
            public void onFail(String reason) {
                hideProgressDialog();
                Toast.makeText(FacebookShareActivity.this, "Post failed due to some error...", Toast.LENGTH_LONG).show();
                finish();
            }
        }
    }

Upvotes: 1

Related Questions