2012년 9월 19일 수요일

안드로이드 페이스북 이미지 포스팅 관련 참조 사이트


출처 : http://stackoverflow.com/questions/5170355/android-send-a-facebook-post-with-custom-actions

http://stackoverflow.com/questions/10975102/image-post-into-facebook-wall-from-android-sdcard


I just wanna post images from my android sdcard into facebook wall.I used below code.But couldn't able to see image post on FB wall.
My code:
private void fbWallPost() {
                facebook = new Facebook("My appId");
                asyncRunner = new AsyncFacebookRunner(facebook);
                facebook.authorize(facebook.this, new String[] { "user_status",
                        "user_about_me", "email", "read_stream",
                        "publish_stream" }, new DialogListener() {

                public void onComplete(Bundle values) {

                    JSONObject jObject;
                    try {
                        jObject = new JSONObject(facebook.request("me"));
                        FileInputStream fis = new FileInputStream(
                                "/sdcard/codeofaninja.jpg");
                        Bitmap bi = BitmapFactory.decodeStream(fis);
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                        data = baos.toByteArray();

                        Bundle params = new Bundle();
                        params.putString("method", "photos.upload");
                        params.putByteArray("picture", data);

                        asyncRunner.request("me/photos", params, "POST",
                                new mRequestListener(), null);

                    } catch (MalformedURLException e) {

                        e.printStackTrace();
                    } catch (JSONException e) {

                        e.printStackTrace();
                    } catch (IOException e) {

                        e.printStackTrace();
                    }
                }

                public void onFacebookError(FacebookError error) {
                    Toast.makeText(facebook.this,
                            "Facebook onFacebookError", Toast.LENGTH_LONG)
                            .show();
                }

                public void onError(DialogError e) {
                    Toast.makeText(facebook.this, "Facebook onError",
                            Toast.LENGTH_LONG).show();
                }

                public void onCancel() {

                }
            });
        }

    });
share|improve this question

36% accept rate


Are you using facbook sdk??? – anoop Jun 11 at 6:12

s.Im using facebook SDK for android – sanjay Jun 11 at 6:14

A link is given bellow. download this code (fb sdk) then in this have 2 class 1 for connect to face book and other for post to facebook. and also use the code in class class "public void postToFacebook" . – anoop Jun 11 at 6:35

In this link example.,ur posting images from URL.But i want to post image from sdcard (like mnt/sdcard/cartoon.jpg) – sanjay Jun 11 at 6:47

Hello brother, You must put some effort in it. "_selectedImagePath" is the path of image from gallery.. You must write a function for select image from gallery and take the path as "_selectedImagePath". – anoop Jun 11 at 6:50
feedback

2 Answers

you can use this code for share image form sdcard
public void shareimage(View v) {


         Intent share = new Intent(Intent.ACTION_SEND);
         share.setType("image/jpeg");

         share.putExtra(Intent.EXTRA_STREAM,Uri.parse(
         "file:///mnt/sdcard/test/v1327056571768.3gpp"));

         startActivity(Intent.createChooser(share, "Share Image"));
}
And also follow following link,I have posted on my Blog.
share|improve this answer


Nope.I dont want to share my images,i just wanna post images into facebook wall.Pls check what mistake ive done on this? – sanjay Jun 11 at 6:18
feedback
public void postToFacebook(String review) throws IOException {
        _mProgress.setMessage("Posting ...");
        _mProgress.show();


        if (_category.equals("Status")) {

            // post status as bundle
            AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(
                    _mFacebook);
            // create object for bundle
            Bundle params = new Bundle();
            params.putString("message", review);
            // This is used to post status to facebook
            mAsyncFbRunner.request("me/feed", params, "POST",
                    new WallPostListener());

        } else {

            // upload picture to fb
            AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(
                    _mFacebook);
            Bundle params = new Bundle();
            // convert to byte stream
            FileInputStream is = new FileInputStream(new File(
                    _selectedImagePath));
            ByteArrayOutputStream bs = new ByteArrayOutputStream();
            // convert picture to byte array
            int data = 0;
            while ((data = is.read()) != -1)
                bs.write(data);
            is.close();
            byte[] raw = bs.toByteArray();
            bs.close();
            // dent message and picture as bundle
            params.putByteArray("picture", raw);
            params.putString("message", review);
            // This is used to post picture to facebook
            mAsyncFbRunner.request("me/photos", params, "POST",
                    new WallPostListener());
        } 
    }
"_selectedImagePath" is the path of image from gallery..
In this i have 2 button 1 for status upload and other for picture upload... 2nd part (else part) for picture upload..
also use this link
In this have all the explanations.

댓글 없음:

댓글 쓰기