如何在Android上使用Facebook SDK 3.0发布消息和图片
链接 - >可以发布带有链接和所有其他信息的小图片。
http://developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog/
我想要的只是在墙上发布带有消息的Pic,而不是带描述的链接?,我需要在自定义按钮点击时发布消息。
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();
}
}
答案 0 :(得分:2)
您可以使用Facebook 请求类的newUploadPhotoRequest()方法。请参阅Post pic on wall with message with Android Facebook SDK 3.0
上接受的答案