-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

バンドルで出力できる変数の詳細は次のとおりです。 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");

また、Facebook へのデータの投稿には AsyncFacebookRunner を使用します。

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 に答える
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 に答える