简体   繁体   中英

Android post image to facebook wall not to Gallery album

I've managed to connect my app and Facebook SDK and I can post photo to Album.

The thing is, I have "active image url" in my globals, and I use the following code to post it to Facebook:

Onclick...
case R.id.tab1_PublishFace:
         Bundle params = new Bundle();
         params.putString("method", "photos.upload");
         Bitmap bi = BitmapFactory.decodeFile(Globals.INSTANCE.activeSetting.f_image_path);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
         imgData = baos.toByteArray();
         params.putByteArray("picture", imgData);
         Globals.INSTANCE.mAsyncRunner.request(null, params, "POST",new SampleUploadListener(), null);
         break;

Now, what happens here is, my photo gets uploaded to default album (named as app is named), and it is not visible to anyone, even though I've manually changed in Facebook settings to be visible to some people. Beside that, my Images on facebook are not automatically placed to Album, but rather request that I approve them.

This is the code how I connect to Facebook and keep the token and session infos in SharedPreferences:

 Globals.INSTANCE.facebook.authorize(getSherlockActivity(), new String[] {"publish_actions"}, new DialogListener() {
                    public void onFacebookError(FacebookError e) {
                        // TODO Auto-generated method stub
                        showToast("FacebookError");
                    }

                    public void onError(DialogError e) {
                        // TODO Auto-generated method stub
                        showToast("FacebookError");
                    }

                    public void onComplete(Bundle values) {
                        // TODO Auto-generated method stub
                        ImageView img = (ImageView) getSherlockActivity().findViewById(R.id.imageView1);
                        TextView txt = (TextView) getSherlockActivity().findViewById(R.id.textView1);
                        txt.setText("Log Out from Facebook");
                        txt.setTag(faceLoggedIn);
                        showToast("Succesfully Loged To FB. Click Again to Logout");
                        SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token", Globals.INSTANCE.facebook.getAccessToken());
                        editor.putLong("access_expires", Globals.INSTANCE.facebook.getAccessExpires());
                        editor.commit();
                    }

                    public void onCancel() {
                        // TODO Auto-generated method stub
                        showToast("Canceled");
                    }
                });

I'm looking at https://github.com/fbsamples/ios-android-wishlist example, and I don't see any special rights set up, and when I compile that example, my photos get published properly and no approval is needed.

What Am I missing, is it Facebook App settings, or something in my code?

I'd like images to be added to album, but to be published on my wall when posted.

Tnx

When you see when you upload a picture in facebook, you post it to a specific album titled "Wall Photos".

this should work:

Bundle params = new Bundle();
params.putByteArray("source", imageBytes);
params.putString("message", "A wall picture");
facebook.request("me/feed", params, "POST");

If that does not work, then you'll have to get the "wall photos" album id of the logged in user first and then do something like:

Bundle params = new Bundle();
params.putByteArray("source", imageBytes);
params.putString("message", "A wall picture");
facebook.request("ALBUM_ID/photos", params, "POST");

see thread :

Post a picture to the wall from android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM