如何在android中使用Graph API在facebook上发布我的状态

如何在android中使用Graph API在facebook上发布我的状态,android,facebook,facebook-graph-api,Android,Facebook,Facebook Graph Api,我想在我的android应用程序中使用Graph API发布使用android应用程序的文本状态,但不知道如何完美地使用API。。。 (我正在使用最新的API) 这是我的登录活动 import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app

我想在我的android应用程序中使用Graph API发布使用android应用程序的文本状态,但不知道如何完美地使用API。。。 (我正在使用最新的API)

这是我的登录活动

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;

import java.util.Arrays;


public class LoginToFacebook extends AppCompatActivity {

    public LoginButton loginButton;
    private CallbackManager callbackManager;
    public static final String LOGGED_IN_PREFFERENCE = "loggedInPrefference" ;
    private AccessToken accessToken;
    LoginResult loginResultOfClass;
    static SharedPreferences mPrefs;

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        if(mPrefs.getBoolean("loggedIn",false)==true);
        {
            Intent i = new Intent(LoginToFacebook.this,PostToWall.class);
            startActivity(i);


        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        mPrefs = getSharedPreferences(LOGGED_IN_PREFFERENCE, Context.MODE_PRIVATE);
        callbackManager = CallbackManager.Factory.create();
        accessToken = AccessToken.getCurrentAccessToken();

        setContentView(R.layout.activity_login_to_facebook);
        loginButton = (LoginButton) findViewById(R.id.login_button);
        loginButton.setReadPermissions(Arrays.asList("user_friends"));


        // Other app specific specialization




        // Callback registration
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // App code

                loginResultOfClass = loginResult;

                SharedPreferences.Editor editor = mPrefs.edit();
                editor.putBoolean("loggedIn",true);
                editor.commit();


                Intent i = new Intent(LoginToFacebook.this,PostToWall.class);
                i.putExtra("UserName", loginResult.getAccessToken().getUserId());
                i.putExtra("AuthToken", loginResult.getAccessToken().getToken());
                startActivity(i);
            }

            @Override
            public void onCancel() {
                // App code

                Toast.makeText(LoginToFacebook.this, "login Cancelled", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(FacebookException exception) {
                // App code
                Toast.makeText(LoginToFacebook.this, "login exception"+exception.toString(), Toast.LENGTH_SHORT).show();

            }
        });




    }





    @Override
    protected void onResume() {
        super.onResume();
        // Logs 'install' and 'app activate' App Events.
        AppEventsLogger.activateApp(this);
    }


    @Override
    protected void onPause() {
        super.onPause();
        // Logs 'app deactivate' App Event.
        AppEventsLogger.deactivateApp(this);
    }

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


}
我不知道为什么GraphRequest不适合我。。。
请帮助我查找错误…

请尝试以下代码:

Bundle postContents = new Bundle();
            String selectedImageURL = galleryObj.getImageURL(mImageSelected);
            mImageStory = mTextBox.getText().toString();

            /*postContents.putString("attachment", "{\"name\":\""+mImageStory+"\","
            +"\"media\":[{\"type\":\"image\",\"src\":\""+selectedImageURL+"\",\"href\":\""+selectedImageURL+"\"}]"
            +"}");*/

//Below code is for posting text only
postContents.putString("attachment", "{\"name\":\""+mImageStory+"\""
            +"}");

            // OLD REST API stream.publish used to publish data onto the wall
            mFacebook.dialog(mContext, "stream.publish", postContents, new AndroidDialogListener());
以下是在墙上张贴带有文本的图像的列表:

public class AndroidDialogListener extends BaseDialogListener {

    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);

            // get the post id and send a request to get it posted on wall
            // once posted/failure then call back invoked
            mAsyncRunner.request(postId, new WallPostRequestListener());

        } else {
            Log.d("Facebook-Example", "No wall post made");
        }
    }
}

那么你是不是遇到了一个错误,或者你能描述一下这个代码是如何工作的吗?没有遇到任何错误,但是我的帖子没有贴到我的墙上。。。我做的笔画是对的。。。
public class AndroidDialogListener extends BaseDialogListener {

    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);

            // get the post id and send a request to get it posted on wall
            // once posted/failure then call back invoked
            mAsyncRunner.request(postId, new WallPostRequestListener());

        } else {
            Log.d("Facebook-Example", "No wall post made");
        }
    }
}