1

我正在尝试使用. 我已经做好了AndoidFaceBook SDK

Facebook fb;
String APP_ID="xxxxx";//xxxxx: is my app id
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";
mShareButton= (Button) findViewById(R.id.share_button);
mShareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

            restoreCredentials(fb);
            messageToPost = "Hello Everyone.";
            if (!fb.isSessionValid()) {
                loginAndPostToWall();


            }
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();
}

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

public void postPhotoToWall() {
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.melody);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    final byte[] data = stream.toByteArray();

    Bundle parameters = new Bundle();
    parameters.putString("message", "Message");
    parameters.putByteArray("picture", data);
    parameters.putString("caption", "test");

    try {
         Log.i("Tests", "got response: " );
        fb.request("me/feed");
        Log.i("Tests", "got response: " );

        String response = fb.request("me/feed", parameters, "POST");
        Log.d("Tests", "got response: " + response);
        if (response == null || response.equals("") || response.equals("false")) {
            showToast("Blank response.");
        } else {
            showToast("Photo posted to your facebook wall!");
        }
    } catch (Exception e) {
        showToast("Failed to post photo to your facebook wall!");
        e.printStackTrace();
    }
}

当我点击分享按钮时,我可以连接到我从中获取 App ID 的帐户。我也不能在墙上贴照片:我只是得到“无法将照片贴到你的 Facebook 墙上!” . 我无法弄清楚问题。请帮助。

4

0 回答 0