출처 : http://stackoverflow.com/questions/5170355/android-send-a-facebook-post-with-custom-actions
http://stackoverflow.com/questions/10975102/image-post-into-facebook-wall-from-android-sdcard


|
I just wanna post images from my android sdcard into facebook wall.I used below code.But couldn't able to see image post on FB wall.
My code:
private void fbWallPost() {
facebook = new Facebook("My appId");
asyncRunner = new AsyncFacebookRunner(facebook);
facebook.authorize(facebook.this, new String[] { "user_status",
"user_about_me", "email", "read_stream",
"publish_stream" }, new DialogListener() {
public void onComplete(Bundle values) {
JSONObject jObject;
try {
jObject = new JSONObject(facebook.request("me"));
FileInputStream fis = new FileInputStream(
"/sdcard/codeofaninja.jpg");
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
asyncRunner.request("me/photos", params, "POST",
new mRequestListener(), null);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void onFacebookError(FacebookError error) {
Toast.makeText(facebook.this,
"Facebook onFacebookError", Toast.LENGTH_LONG)
.show();
}
public void onError(DialogError e) {
Toast.makeText(facebook.this, "Facebook onError",
Toast.LENGTH_LONG).show();
}
public void onCancel() {
}
});
}
});
|
|
feedback
|
|
you can use this code for share image form sdcard
public void shareimage(View v) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse(
"file:///mnt/sdcard/test/v1327056571768.3gpp"));
startActivity(Intent.createChooser(share, "Share Image"));
}
And also follow following link,I have posted on my Blog.
|
|
feedback
|


|
public void postToFacebook(String review) throws IOException {
_mProgress.setMessage("Posting ...");
_mProgress.show();
if (_category.equals("Status")) {
// post status as bundle
AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(
_mFacebook);
// create object for bundle
Bundle params = new Bundle();
params.putString("message", review);
// This is used to post status to facebook
mAsyncFbRunner.request("me/feed", params, "POST",
new WallPostListener());
} else {
// upload picture to fb
AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(
_mFacebook);
Bundle params = new Bundle();
// convert to byte stream
FileInputStream is = new FileInputStream(new File(
_selectedImagePath));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
// convert picture to byte array
int data = 0;
while ((data = is.read()) != -1)
bs.write(data);
is.close();
byte[] raw = bs.toByteArray();
bs.close();
// dent message and picture as bundle
params.putByteArray("picture", raw);
params.putString("message", review);
// This is used to post picture to facebook
mAsyncFbRunner.request("me/photos", params, "POST",
new WallPostListener());
}
}
"_selectedImagePath" is the path of image from gallery..
In this i have 2 button 1 for status upload and other for picture upload... 2nd part (else part) for picture upload..
In this have all the explanations.
|