-1

我一直在寻找很多方法来做到这一点。但似乎没有什么对我有用。有人可以帮忙吗?

这是我的 Facebook 状态帖子的图像按钮:

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/hoributtons"
    android:layout_alignTop="@+id/imageButton2"
    android:background="#00000000"
    android:contentDescription="@string/facebook"
    android:onClick="shareOnFacebook"
    android:src="@drawable/facebookbutton" />

这是我的 mainactivity.java 文件的对应部分:

public class MainActivity extends FacebookActivity {

    private static final String APP_ID = "xxxxxxxxxxxxx";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }



public void shareOnFacebook(View v) {
        //mfacebook = new Facebook("xxxxxxxxxxxxx");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

有人可以指出正确的方向吗?:)

4

3 回答 3

11

假设您想在自己的墙上发帖(因为问题不清楚),这应该适合您。

public class MainActivity extends Activity {
        private static final String APP_ID = "xxxxxxxxxxxxx";
        private Facebook mFacebook;
        private AsyncFacebookRunner mAsyncRunner;
        private EditText yourEditText;
        private String toShare;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mFacebook = new Facebook();
            mAsyncRunner = new AsyncFacebookRunner(mFacebook);
            SessionEvents.addAuthListener(new SampleAuthListener());
            SessionEvents.addLogoutListener(new SampleLogoutListener());
            yourEditText = (EditText) findViewById(R.id.<youreditTextId>);
            toShare = yourEditText.getText().toString();
        }

        public void shareOnFacebook(View v) {
            Bundle params = new Bundle();
            params.putString("message", toShare);

            mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
                public void onMalformedURLException(MalformedURLException e) {}
                public void onIOException(IOException e) {}
                public void onFileNotFoundException(FileNotFoundException e) {}
                public void onFacebookError(FacebookError e) {}
                public void onComplete(String response) {
            }
        }); 

        Toast.makeText(MainActivity.this, "Posting to your Wall", Toast.LENGTH_SHORT).show();  

          }

     }

有关将图片发布到墙上的详细信息,Facebook有一个很好的文档。

于 2012-12-11T09:49:15.193 回答
2

使用您的android应用程序成功登录的用户墙上发布消息的最简单方法是(我的工作代码)_

public class AndroidFacebookWallPost extends Activity {

// Your Facebook APP ID:
private static String APP_ID = "your App ID here"; //

// Instance of Facebook Class:
private Facebook facebook;
private AsyncFacebookRunner mAsyncRunner;

// Your ImageButton that Post Message to Facebook Wall:
ImageButton btnPostToWall;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btnPostToWall = (ImageButton) findViewById(R.id.imageButton1);// Your image button...

    facebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(facebook);
    // set listener for Post Message button
    btnPostToWall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            postToWall();
        }
    });

}

/**
 * Method that Post a Text Status using Facebook API on user`s wall.
 */
public void postToWall() {
    // post on user's wall.
    facebook.dialog(this, "feed", new DialogListener() {

        @Override
        public void onFacebookError(FacebookError error) {
            Toast.makeText(AndroidFacebookWallPost.this, "Post fail "+error, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(DialogError error) {
            Toast.makeText(AndroidFacebookWallPost.this, "Post fail due to "+error, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onComplete(Bundle values) {
            Toast.makeText(AndroidFacebookWallPost.this, "Post success.", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(AndroidFacebookWallPost.this, "Cancle by user!", Toast.LENGTH_LONG).show();
        }
    });

}

}

有关更多信息,请参阅Android 版 Facebook SDK 入门

于 2012-12-16T15:56:28.837 回答
2

这是您可以捆绑销售的变量的详细信息 Bundle params = new Bundle();

params.putString("message", "This string will appear as the status message");
    params.putString("link", "This is the URL to go to");
    params.putString("name", "This will appear beside the picture");
    params.putString("caption", "This will appear under the title");
    params.putString("description", "This will appear under the caption");
    params.putString("picture", "This is the image to appear in the post");

并使用 AsyncFacebookRunner 将数据发布到 facebook :

mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
            public void onMalformedURLException(MalformedURLException e) {}
            public void onIOException(IOException e) {}
            public void onFileNotFoundException(FileNotFoundException e) {}
            public void onFacebookError(FacebookError e) {}
            public void onComplete(String response) {
        }
    });
于 2012-12-19T04:33:18.513 回答