を使用して Facebook でアプリケーションから写真を共有しようとしています。私はやったAndoid
FaceBook 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();
}
}
共有ボタンをクリックすると、アプリ ID を取得したアカウントだけに接続できます。また、ウォールに写真を投稿できません。「Facebook ウォールに写真を投稿できませんでした!」というメッセージが表示されます。. 問題がわかりません。どなたか助けてください。