Android Facebook帖子未显示

Android Facebook帖子未显示,android,facebook,Android,Facebook,我在facebook开发者网站上创建了一个应用程序,并在我的应用程序中使用了appId,然后尝试在facebook上发布。当我在应用程序中使用相同的fb帐户登录并使用facebook发布时,它成功发布,但当我尝试使用不同的帐户登录时,它没有发布……任何人都能帮助我 import java.util.ArrayList; import java.util.List; import org.json.JSONException; import org.json.JSONObject; impor

我在facebook开发者网站上创建了一个应用程序,并在我的应用程序中使用了appId,然后尝试在facebook上发布。当我在应用程序中使用相同的fb帐户登录并使用facebook发布时,它成功发布,但当我尝试使用不同的帐户登录时,它没有发布……任何人都能帮助我

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.facebook.FacebookRequestError;
import com.facebook.HttpMethod;
import com.facebook.Request;
import com.facebook.RequestAsyncTask;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionLoginBehavior;
import com.facebook.SessionState;
import com.suppliers.bee2buy.R;
import com.suppliers.utils.AppPreferences;

public class ShareData extends Activity {
    private Session.StatusCallback sessionStatusCallback;
    private Session currentSession;
    Button publishButton;
    AppPreferences appPref;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sharedata);
        appPref = new AppPreferences(ShareData.this, "PREFS");
        publishButton = (Button) findViewById(R.id.publishButton);

        connectToFB();

        publishButton.setVisibility(View.VISIBLE);

        // create instace for sessionStatusCallback
        sessionStatusCallback = new Session.StatusCallback() {

            @Override
            public void call(Session session, SessionState state,
                    Exception exception) {
                onSessionStateChange(session, state, exception);

            }
        };

        // logout button

        // publish button
        publishButton = (Button) findViewById(R.id.publishButton);
        publishButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                publishStorys();

            }
        });

    }

    /**
     * Connects the user to facebook
     */
    public void connectToFB() {

        List<String> permissions = new ArrayList<String>();
        permissions.add("publish_stream");


        currentSession = new Session.Builder(this).build();
        currentSession.addCallback(sessionStatusCallback);

        Session.OpenRequest openRequest = new Session.OpenRequest(
                ShareData.this);
        openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        openRequest.setRequestCode(Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE);
        openRequest.setPermissions(permissions);
        currentSession.openForPublish(openRequest);

    }

    /**
     * this method is used by the facebook API
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (currentSession != null) {
            currentSession
                    .onActivityResult(this, requestCode, resultCode, data);
        }
    }

    /**
     * manages the session state change. This method is called after the
     * <code>connectToFB</code> method.
     * 
     * @param session
     * @param state
     * @param exception
     */
    private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {
        if (session != currentSession) {
            return;
        }

        if (state.isOpened()) {
            // Log in just happened.
            Toast.makeText(getApplicationContext(), "session opened",
                    Toast.LENGTH_SHORT).show();
        } else if (state.isClosed()) {
            // Log out just happened. Update the UI.
            Toast.makeText(getApplicationContext(), "session closed",
                    Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * Publishes story on the logged user's wall
     */

    private void publishStorys() {
        if (currentSession != null) {
            // this is not used
            // Bitmap icon =
            // BitmapFactory.decodeResource(getApplicationContext()
            // .getResources(), R.drawable.ic_launcher);

            Bundle postParams = new Bundle();
            postParams.putString("name", "Product Shared from Bee2Buy");
            postParams.putString("caption", appPref.getData("share_title"));
            // postParams
            // .putString(
            // "description",
            // "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
            postParams.putString(
                    "link",
                    "http://www.saznaitsols.com/site_uploads/product/"
                            + appPref.getData("share_img"));
            postParams.putString(
                    "picture",
                    "http://www.saznaitsols.com/site_uploads/product/"
                            + appPref.getData("share_img"));

            Request.Callback callback = new Request.Callback() {
                public void onCompleted(Response response) {

                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Toast.makeText(ShareData.this.getApplicationContext(),
                                error.getErrorMessage(), Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        // Toast.makeText(
                        // ShareData.this.getApplicationContext(),
                        // postId, Toast.LENGTH_LONG).show();
                    }
                }
            };

            Request request = new Request(currentSession, "me/feed",
                    postParams, HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
            Toast.makeText(ShareData.this, "Posted on fb", Toast.LENGTH_SHORT).show();
            ShareData.this.finish();


        } else {
            Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG)
                    .show();
        }

    }

}

您应该根据您想在用户墙上发布内容的时间请求
publish\u actions
权限


如果使用不同的帐户,是否看到“权限”对话框?我怀疑你尝试的第一个用户是你应用程序的管理员,而第二个不是。这就是为什么它对第一个有效。

感谢托比的回复。。我已经找到了另一个在facebook上共享数据的解决方案,使用facebook团队推荐的feed对话框,如果你对你在facebook上发布的内容的额外对话框满意,我们可以使用这种方法。但是要确保我们已经像托比说的那样给予了所有的许可

   private void publishFeedDialog() {
            Bundle params = new Bundle();
            params.putString("name", "Product shared from Bee2buy");
            params.putString("caption",
                    appPref.getData("share_title"));

            params.putString("link", "http://www.saznaitsols.com/site_uploads/product/"
                    + appPref.getData("share_img"));
            params.putString("picture",
                    "http://www.saznaitsols.com/site_uploads/product/"
                            + appPref.getData("share_img"));

            WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(
                    ShareData.this, currentSession, 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(ShareData.this,
                                            "Posted story, id: " + postId,
                                            Toast.LENGTH_SHORT).show();
                                } else {
                                    // User clicked the Cancel button
                                    Toast.makeText(
                                            ShareData.this
                                                    .getApplicationContext(),
                                            "Publish cancelled", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            } else if (error instanceof FacebookOperationCanceledException) {
                                // User clicked the "x" button
                                Toast.makeText(
                                        ShareData.this.getApplicationContext(),
                                        "Publish cancelled", Toast.LENGTH_SHORT)
                                        .show();
                            } else {
                                // Generic, ex: network error
                                Toast.makeText(
                                        ShareData.this.getApplicationContext(),
                                        "Error posting story", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }



                    }).build();
            feedDialog.show();
        }

上面的方法有一些问题,它可以很好地与旧的SDK的,但与新的它不工作!!至少对我来说它不起作用