问题
I'm currently able to post to a public page wall using:
JSONObject json = new JSONObject();
json.put("message", "I'm on your wall");
Request req = Request.newPostRequest(getSession(), "PowerCardSoftware/feed", GraphObject.Factory.create(json), new Callback() {
@Override
public void onCompleted(Response response) {
if(response.getError() != null)
Log.e("FRAGACTIVITY", response.getError().toString());
Toast.makeText(getBaseContext(), "I hacked your facebook!", Toast.LENGTH_SHORT).show();
}
});
Request.executeBatchAsync(req);
I would like to post a picture the user takes onto the public wall as well. I've tried using a Bundle instead of a JSONObject and using each of these lines:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
postPhoto.compress(CompressFormat.JPEG, 100, baos);
params.putByteArray("picture", baos.toByteArray());
params.putByteArray("source", baos.toByteArray());
They both give me an error like this - errorMessage: (#100) picture URL is not properly formatted
Anyone know how to post a photo onto someone else's facebook wall without using deprecated functions/Objects in the facebook sdk?
回答1:
This is my code to upload a photo stored locally on the phone:
Request request6 = Request.newUploadPhotoRequest(
session,
((BitmapDrawable) getResources().getDrawable(
R.drawable.picture)).getBitmap(), callback6);
RequestAsyncTask task6 = new RequestAsyncTask(request6);
task6.execute();
This is to upload on your own wall. Reason why there is no option to choose another recipient is due to the breaking changes in February that will disable posting to other people's wall.
See my earlier answer.
EDIT:
what is the best way to upload a photo that will show up on a place's wall with a photo and message?
Can you try this and see if this works?
Bundle parameters = new Bundle();
parameters.putParcelable("picture", YOUR_BITMAP_HERE);
parameters.putString("message", "my message for the page");
return new Request(session, "PowerCardSoftware/feed", parameters, HttpMethod.POST, callback);
Can I add a message using newUploadPhotoRequest()?
No, to add a message with your photo, you won't be using newUploadPhotoRequest
. If you dig into the source, its just a wrapper of a Request
, so do the same as the method, but add an additional parameter, message
, with the message you want, and execute it. I haven't personally verified it but it should work. Let me know if it doesn't.
回答2:
This is my solution. I referenced Jesse Chen's answer and made some modifications.
Bitmap image = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "demo.jpg");
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) {
showPublishResult(mainActivity.getString(R.string.photo_post), response.getGraphObject(), response.getError());
}
});
request.executeAsync();
回答3:
You can check facebookSDK project /tests folders and search keywords newPostRequest. the sample code is as below
GraphObject statusUpdate = GraphObject.Factory.create();
String message = "message";
statusUpdate.setProperty("message", message);
statusUpdate.setProperty("link", "http://stackoverflow.com/questions/14129546/android-post-picture-to-facebook-public-page-wall#");
Request request = Request.newPostRequest(Session.getActiveSession(), "me/feed", statusUpdate, new Callback() {
@Override
public void onCompleted(Response response) {
}
});
request.executeAsync();
来源:https://stackoverflow.com/questions/14129546/android-post-picture-to-facebook-public-page-wall