Reputation: 67
How can i post message along with Picture using Facebook SDK 3.0 on Android,
The link -> can post small pic with link and all other information.
http://developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog/
What i want, is only to post Pic on wall with message, not a link with description ?, i need to post it with message on custom button click.
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null){
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
FileInputStream fis = null;
try {
fis = new FileInputStream(imagepath);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
Bitmap b = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
Bundle postParams = new Bundle();
postParams.putString("message", "Facebook SDK for Android ");
postParams.putByteArray("source",byteArray);
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i("JSON error ","JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), postId,Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams,HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
Upvotes: 3
Views: 180
Reputation: 1613
You can use newUploadPhotoRequest() method of the Facebook Request class. Please refer the accepted answer at Post pic on wall with message with Android Facebook SDK 3.0
Upvotes: 2