Reputation: 11164
I am using the next code to post an image to the user's Facebook wall:
private void postImageToWall(Session session) {
// Bitmap image = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "demo.jpg");
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.frame_with_woman);
Bundle parameters = new Bundle();
parameters.putParcelable("source", image);
parameters.putString("message", "my message for the page");
Request request = new Request(Session.getActiveSession(), "me/photos", parameters, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
LogService.log(TAG, "Successfully posted");
}
});
request.executeAsync();
}
How can I make it so a "default" Facebook popup dialog appears (you know the ones, e.g. this one) thus letting the user enter the caption of the image, and not set a hard-coded one, like I am in the code above.
parameters.putString("message", "my message for the page");
Upvotes: 1
Views: 191
Reputation: 12134
User this tag for description posting,
postParams.putString("caption", mes);
This is my complete code for sharing image with text in facebook wall,
private void facebookImagePosting(String imageUrl, String mes) {
Bundle postParams = new Bundle();
postParams.putString("access_token", accessToken);
byte[] data = null;
URL aURL;
BufferedInputStream bis = null;
try {
aURL = new URL(imageUrl);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
bis = new BufferedInputStream(is, 8192);
} catch (Exception e) {
e.printStackTrace();
}
Bitmap bi = BitmapFactory.decodeStream(bis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParams.putByteArray("picture", data);
postParams.putString("caption", mes);
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
FacebookRequestError error = response.getError();
if (error != null) {
Log.e("Facebook Error Message", error.getErrorMessage());
} else {
Log.e("Success Message", "Decision posted successfully!");
}
}
};
Request request = new Request(Session.getActiveSession(), "me/photos",
postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
Upvotes: 0
Reputation: 5784
Try using following method for posting message
void PostFb()
{
Bundle parameters = new Bundle();
parameters.putString("name", getResources().getString(R.string.app_name));
parameters.putString("link", "http://www.youtube.com");//Put Image URL Here
facebook.dialog(this, "stream.publish", parameters,
new DialogListener() {
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
e.printStackTrace();
}
public void onComplete(Bundle values) {
}
public void onCancel() {
}
});
}
let me know if it works.Because it shows preview of any url you enter at this line parameters.putString("link", "http://www.youtube.com");
Before doing this declare below parameters
Declare this above class name private Facebook facebook;
& Do initialization like this at onCreate
method
facebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(facebook);
Upvotes: 1