Upload image / photo / image facebook (android)

I use the official Facebook library and post photos beautifully. But I doubt it. When you send a message for the first time, an image appears in the message above the wall. But when you publish a second time, it does not create a new post, the previous message is edited and says "2 pictures added."

If the message is at the bottom of the wall and will publish the photo again, we will not see a single message at the top, it will be released in the internal message. It will be hidden. Can you create a new post every time I upload a photo? How is this possible?

I shared with you my work with the code, and anyone can help. Thanks.

OnClick:

mFacebook = new Facebook(APP_ID); mFacebook.authorize(Principal.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() { @Override public void onComplete(Bundle values) { postImageonWall(); } @Override public void onFacebookError(FacebookError error) { } @Override public void onError(DialogError e) { } @Override public void onCancel() { } }); 

Postwall:

 public void postImageonWall() { byte[] data = null; Bitmap bi = BitmapFactory.decodeFile(fotomontatgeInSD); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); data = baos.toByteArray(); Bundle params = new Bundle(); params.putString(Facebook.TOKEN, mFacebook.getAccessToken()); params.putString("method", "photos.upload"); params.putByteArray("picture", data); AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook); mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); } public class SampleUploadListener extends BaseRequestListener { public void onComplete(final String response, final Object state) { try { // process the response here: (executed in background thread) Log.d("Facebook-Example", "Response: " + response.toString()); JSONObject json = Util.parseJson(response); final String src = json.getString("src"); // then post the processed result back to the UI thread // if we do not do this, an runtime exception will be generated // eg "CalledFromWrongThreadException: Only the original // thread that created a view hierarchy can touch its views." } catch (JSONException e) { Log.w("Facebook-Example", "JSON Error in response"); } catch (FacebookError e) { Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); } } @Override public void onFacebookError(FacebookError e, Object state) { // TODO Auto-generated method stub } } 

I just discovered that the new facebook design solves this problem.

+4
source share
2 answers

Try changing your code:

 mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener(), null); 
0
source

private void sharePhotoToFacebook () {Bitmap = BitmapFactory.decodeResource (getResources (), R.drawable.f1);

  SharePhoto photo = new SharePhoto.Builder() .setBitmap(image) .build(); SharePhotoContent content = new SharePhotoContent.Builder() .addPhoto(photo) .build(); ShareApi.share(content, null); } 
0
source

Source: https://habr.com/ru/post/1387337/


All Articles