0
自分のアンドロイドアプリから画像とテキストをFacebookの壁に投稿しようとしています。私はモバイルギャラリーから画像を選択する必要がありますが、動作しません。私はこのコードで何が問題になっているのかわかりません。誰も助けてくれますか?ギャラリーから選択した画像をFacebookの壁面にAndroid appから投稿する方法は?
public class PostFacebook extends Activity{
private Facebook mFacebook;
private CheckBox mFacebookCb;
private ProgressDialog mProgress;
private static final int SELECT_PICTURE = 100;
byte[] inputData;
Uri selectedImageUri;
String imgString;
ImageView image;
private Handler mRunOnUi = new Handler();
private static final String APP_ID = "7************";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fbpost);
final EditText reviewEdit = (EditText) findViewById(R.id.revieew);
image = (ImageView) findViewById(R.id.imageView1);
mFacebookCb = (CheckBox) findViewById(R.id.cb_facebook);
mProgress = new ProgressDialog(this);
mFacebook = new Facebook(APP_ID);
SessionStore.restore(mFacebook, this);
if (mFacebook.isSessionValid()) {
mFacebookCb.setChecked(true);
String name = SessionStore.getName(this);
name = (name.equals("")) ? "Unknown" : name;
mFacebookCb.setText(" Facebook (" + name + ")");
}
((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String review = reviewEdit.getText().toString();
try {
InputStream iStream = getContentResolver().openInputStream(selectedImageUri);
inputData = GetImage.getBytes(iStream);
imgString = Base64.encodeToString(inputData, Base64.DEFAULT);
Log.v("image_check", imgString);
Toast.makeText(PostFacebook.this, imgString, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (review.equals(""))
return;
if (mFacebookCb.isChecked()) postToFacebook(review, imgString);
}
});
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
}
});
}
private void postToFacebook(String review, String image) {
mProgress.setMessage("Posting ...");
mProgress.show();
AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);
Bundle params = new Bundle();
params.putString("message", review);
params.putString("picture", image);
params.putString("name", "Hira Ghaffar");
params.putString("caption", "Innovent.net");
params.putString("description", "Innovent is an android app developed by iFish Technologies");
mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());
}
private final class WallPostListener extends BaseRequestListener {
public void onComplete(final String response) {
mRunOnUi.post(new Runnable() {
@Override
public void run() {
mProgress.cancel();
Toast.makeText(PostFacebook.this, "Posted to Facebook", Toast.LENGTH_SHORT).show();
}
});
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
selectedImageUri = data.getData();
if (null != selectedImageUri) {
image.setImageURI(selectedImageUri);
}
}
}
}
}
Facebookにあなたのアプリを登録しましたか? – androgo
いいえ私は@androgoをしませんでした – hira
それを見てくださいhttps://developers.facebook.com/docs/sharing/android。あなたのマニフェストファイルを見ることができますか? – androgo