Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 想将我的编辑文字信息发布到facebook墙吗_Android_Facebook - Fatal编程技术网

Android 想将我的编辑文字信息发布到facebook墙吗

Android 想将我的编辑文字信息发布到facebook墙吗,android,facebook,Android,Facebook,我有一个活动,其中包含一个编辑文本和一个按钮,用于将此编辑文本消息共享到facebook。但是我的编辑短信没有穿过facebook的墙。我已经集成了facebook sdk。谁能帮帮我 import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; impor

我有一个活动,其中包含一个编辑文本和一个按钮,用于将此编辑文本消息共享到facebook。但是我的编辑短信没有穿过facebook的墙。我已经集成了facebook sdk。谁能帮帮我

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
           import android.widget.Toast;

         import com.facebook.android.DialogError;
         import com.facebook.android.Facebook;
          import com.facebook.android.Facebook.DialogListener;
             import com.facebook.android.FacebookError;

public class FacebookpostScreen extends Activity{

    private static final String APP_ID = "myappid";
    private static final String[] PERMISSIONS = new String[] {"publish_stream"};

    private static final String TOKEN = "access_token";
        private static final String EXPIRES = "expires_in";
        private static final String KEY = "facebook-credentials";

    private Facebook facebook;
    private String messageToPost;

    public boolean saveCredentials(Facebook facebook) {
            Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
            editor.putString(TOKEN, facebook.getAccessToken());
            editor.putLong(EXPIRES, facebook.getAccessExpires());
            return editor.commit();
        }

        public boolean restoreCredentials(Facebook facebook) {
            SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
            facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
            facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
            return facebook.isSessionValid();
        }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        facebook = new Facebook(APP_ID);
        restoreCredentials(facebook);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.facebookpostscreen);

        String facebookMessage = getIntent().getStringExtra("filteredMessage");
        if (facebookMessage == null){
            facebookMessage = "Test wall post";
        }
        messageToPost = facebookMessage;
    }

    public void doNotShare(View button){
        finish();
    }
    public void share(View button){
        if (! facebook.isSessionValid()) {
            loginAndPostToWall();
        }
        else {
            postToWall(messageToPost);
        }
    }

    public void loginAndPostToWall(){
         facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
    }

    public void postToWall(String message){
        Log.d("Tests", "Testing graph API wall post");
        try {
               String response = facebook.request("me");
               Bundle parameters = new Bundle();
               parameters.putString("message", message);
               parameters.putString("description", "test test test");
               response = facebook.request("me/feed", parameters, 
                       "POST");
               Log.d("Tests", "got response: " + response);
               if (response == null || response.equals("") || 
                       response.equals("false")) {
                  Log.v("Error", "Blank response");
            }
            else {
                showToast("Message posted to your facebook wall!");
            }
            finish();
        } catch (Exception e) {
            showToast("Failed to post to wall!");
            e.printStackTrace();
            finish();
        }
    }

    class LoginDialogListener implements DialogListener {
        public void onComplete(Bundle values) {
            saveCredentials(facebook);
            if (messageToPost != null){
            postToWall(messageToPost);
        }
        }
        public void onFacebookError(FacebookError error) {
            showToast("Authentication with Facebook failed!");
            finish();
        }
        public void onError(DialogError error) {
            showToast("Authentication with Facebook failed!");
            finish();
        }
        public void onCancel() {
            showToast("Authentication with Facebook cancelled!");
            finish();
        }
    }

    private void showToast(String message){
        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
    }
}
请勾选此选项 也许它能帮助你

private void updateStatus() {
            Session session = Session.getActiveSession();
            String _statusMessage = EDT_STATUS_MSG.getText().toString();//ur edit text value

            Log.i(TAG, _statusMessage);
            if (session != null) {

                      Bundle postParams = new Bundle();
                postParams.putString("message", _statusMessage);// the status message to wall
                Request.Callback callback = new Request.Callback() {
                    public void onCompleted(Response response) {
                        JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                        String postId = null;
                        try {
                            postId = graphResponse.getString("id");
                        } catch (JSONException e) {
                            Log.i(TAG, "JSON error " + e.getMessage());
                        }
                        FacebookRequestError error = response.getError();
                        if (error != null) {
                            Toast.makeText(getActivity().getApplicationContext(), error.getErrorMessage(), Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(getActivity().getApplicationContext(), "Post Id of status msg = " + postId, Toast.LENGTH_LONG).show();
                        }
                    }
                };

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

                RequestAsyncTask task = new RequestAsyncTask(request);
                task.execute();
            }
        }

您在OnFacebookeError或OneError方法中收到了什么错误?它正在以空白消息打开facebook的共享活动。事实上,我的应用程序消息没有传递到facebook Post。您没有将消息传递到dialog。您必须找到用于传递消息文本的url参数的名称,然后您应该使用此参数创建捆绑包并将其传递给dialog方法