Android使用facebook sdk上传图像包

时间:2014-05-22 15:59:35

标签: android facebook-graph-api facebook-sdk-3.1

我正在尝试使用Facebook SDK将一组图像发布到Facebook。我尝试使用grap.facebook和RequestBatch。所有图像都已上传,但每张图片都显示在一个帖子中。如何在Android中以原生Facebook应用程序的单个帖子发布所有这些图像?

这是使用RequestBatch和3张图片的代码

    RequestBatch requestBatch = new RequestBatch();
    for (int i = 0; i < 3; i++) {
        Request request = Request.newUploadPhotoRequest(
                Session.getActiveSession(), img, new Request.Callback() {

                    @Override
                    public void onCompleted(Response response) {
                        Toast.makeText(MainActivity.this,
                                "Post photo success", Toast.LENGTH_LONG)
                                .show();
                    }
                });
        Bundle params = request.getParameters();
        params.putString("message", "Caption of picture " + i);
        params.putString("relative_url", "me/photos");
        request.setParameters(params);
        requestBatch.add(request);
    }

    requestBatch.executeAsync();

这里是使用图表

Thread t=new Thread(new Runnable() {                
        @Override
            public void run() {
                try {
                    List<File> files=new ArrayList<File>();
                    JSONArray array = new JSONArray();
                    String tokken=session.getAccessToken();
                    for (int i = 0; i < 3; i++) {
                        JSONObject object = new JSONObject();
                        object.put("method", "POST");
                        object.put("relative_url", "me/photos");
                        object.put("body", "title=Test title&message=Caption of picture " + i);
                        object.put("attached_files", "file" + i);
                        array.put(object);
                        files.add(img);
                    }
                    HttpResponse response= new UploaderImageFacebookUploadUlti().uploadUserPhoto(tokken, "https://graph.facebook.com", array, files);
                    Log.d("response", response.getEntity().toString());
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        t.start();

注意:UploaderImageFacebookUploadUlti只是通过Facebook的演示使用多路径上传的代码:https://developers.facebook.com/docs/graph-api/making-multiple-requests/

我需要在一个帖子中显示所有图片,你有任何解决方案吗?

0 个答案:

没有答案