使用android将照片共享到facebook用户墙

使用android将照片共享到facebook用户墙,android,facebook-android-sdk,Android,Facebook Android Sdk,如何在Android上使用Facebook SDK 3.0发布消息和图片 链接->可以发布带有链接和所有其他信息的小图片 我想要的是,只是张贴在墙上的图片与信息,而不是一个与描述?的链接,我需要发布它与自定义按钮点击消息 private void publishStory() { Session session = Session.getActiveSession(); if (session != null){ List<

如何在Android上使用Facebook SDK 3.0发布消息和图片

链接->可以发布带有链接和所有其他信息的小图片

我想要的是,只是张贴在墙上的图片与信息,而不是一个与描述?的链接,我需要发布它与自定义按钮点击消息

private void publishStory() {


        Session session = Session.getActiveSession();

        if (session != null){


            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(PERMISSIONS, permissions)) {
                pendingPublishReauthorization = true;
                Session.NewPermissionsRequest newPermissionsRequest = new Session
                        .NewPermissionsRequest(this, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
                return;
            }



            FileInputStream fis = null;
            try {

                fis = new FileInputStream(imagepath);

            } catch (FileNotFoundException e1) {

                e1.printStackTrace();
            }

            Bitmap b = BitmapFactory.decodeStream(fis);
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
              b.compress(Bitmap.CompressFormat.JPEG, 100, stream);
              byte[] byteArray = stream.toByteArray();



            Bundle postParams = new Bundle();
            postParams.putString("message", "Facebook SDK for Android ");

              postParams.putByteArray("source",byteArray);

            Request.Callback callback= new Request.Callback() {
                public void onCompleted(Response response) {
                    JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                    String postId = null;
                    try {
                        postId = graphResponse.getString("id");
                    } catch (JSONException e) {
                        Log.i("JSON error ","JSON error "+ e.getMessage());
                    }
                    FacebookRequestError error = response.getError();

                    if (error != null) {

                        Toast.makeText(getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();

                    } else {

                        Toast.makeText(getApplicationContext(), postId,Toast.LENGTH_LONG).show();

                    }
                }
            };

            Request request = new Request(session, "me/feed", postParams,HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
        }

    }
private void publishStory(){
Session=Session.getActiveSession();
if(会话!=null){
List permissions=session.getPermissions();
如果(!isSubsetOf(权限、权限)){
pendingPublishReauthorization=真;
Session.newpermissions请求newpermissions请求=新会话
.NewPermissionsRequest(此,权限);
session.requestNewPublishPermissions(newPermissionsRequest);
返回;
}
FileInputStream fis=null;
试一试{
fis=新文件输入流(imagepath);
}捕获(FileNotFoundException e1){
e1.printStackTrace();
}
位图b=BitmapFactory.decodeStream(fis);
ByteArrayOutputStream=新建ByteArrayOutputStream();
b、 压缩(位图.CompressFormat.JPEG,100,流);
byte[]byteArray=stream.toByteArray();
Bundle postParams=新Bundle();
putString(“消息”,“Android版Facebook SDK”);
postParams.putByteArray(“来源”,byteArray);
Request.Callback=new Request.Callback(){
未完成公共无效(响应){
JSONObject graphResponse=response.getGraphObject().getInnerJSONObject();
字符串postId=null;
试一试{
postId=graphResponse.getString(“id”);
}捕获(JSONException e){
Log.i(“JSON错误”,“JSON错误”+e.getMessage());
}
FacebookRequestError=response.getError();
if(错误!=null){
Toast.makeText(getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();
}否则{
Toast.makeText(getApplicationContext(),postId,Toast.LENGTH_LONG.show();
}
}
};
请求=新请求(会话“me/feed”、后参数、HttpMethod.POST、回调);
RequestAsyncTask任务=新的RequestAsyncTask(请求);
task.execute();
}
}

您可以使用Facebook请求类的newUploadPhotoRequest()方法。请参阅