0

我正在尝试让我的 Android 应用程序将 URI 图像共享到 facebook。使用图片参数时,它会强制您使用图片的 URL。由于我试图从我的手机图库中分享,我想知道是否有办法让 URI 像 URL 一样读取,或者任何其他方式来做到这一点。有什么建议么?

更新:我已经通过添加我尝试使用的代码来更新它。我了解我没有使用 Facebook 新推出的 API。我只想能够将我手机图库中的图片发布到 Facebook,而不是 URL 中的图片。谢谢!

private String[] arrPath;
int id = viewIt.getId();
if(facebook.isSessionValid()) {
                                        Bundle params = new Bundle();
                                        params.putString("name", "AndroidApp");
                                        params.putString("caption", "Application for Android");
                                        params.putString("description", "This is a description");
                                        params.putString("link", "http://www.google.com/");
                                        params.putString("picture", "file://" + arrPath[id]);

                                        facebook.dialog(AndroidClass.this, "feed", params, new DialogListener() {

                                            @Override
                                            public void onFacebookError(FacebookError e) {
                                                // TODO Auto-generated method stub

                                            }

                                            @Override
                                            public void onError(DialogError e) {
                                                // TODO Auto-generated method stub

                                            }

                                            @Override
                                            public void onComplete(Bundle values) {
                                                // TODO Auto-generated method stub

                                            }

                                            @Override
                                            public void onCancel() {
                                                // TODO Auto-generated method stub

                                            }
                                        });
                                    }else {
                                        facebook.authorize(AndroidClass.this, new String[] {"email", "publish_stream"}, new DialogListener() {

                                            @Override
                                            public void onFacebookError(FacebookError e) {
                                                // TODO Auto-generated method stub
                                                Toast.makeText(AndroidClass.this, "fberror", Toast.LENGTH_SHORT).show();
                                            }

                                            @Override
                                            public void onError(DialogError e) {
                                                // TODO Auto-generated method stub
                                                Toast.makeText(AndroidClass.this, "onError", Toast.LENGTH_SHORT).show();
                                            }

                                            @Override
                                            public void onComplete(Bundle values) {
                                                // TODO Auto-generated method stub
                                                Editor editor = sp.edit();
                                                editor.putString("access_token", facebook.getAccessToken());
                                                editor.putLong("access_expires", facebook.getAccessExpires()); 
                                                editor.commit();

                                            }

                                            @Override
                                            public void onCancel() {
                                                // TODO Auto-generated method stub
                                                Toast.makeText(AndroidClass.this, "onCancel", Toast.LENGTH_SHORT).show();

                                            }
                                        });
                                    }
                                }

                            });
4

1 回答 1

0

您可以从 URI 打开到图像的流,然后使用ContentResolver.

Session session = Session.getActiveSession();
Bitmap photo = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
Request request = Request.newUploadPhotoRequest(session, photo, new Request.Callback());
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
于 2013-08-13T00:25:30.727 回答