2

我一直在按照教程在这里创建一个开放的图表故事。一切都很好,但我希望上传的图像很大,即“用户生成”。

我的问题在于实际实施。这是从 SD 卡获取图像的代码:

// If uploading an image, set up the first batch request
 // to do this.
     // Set up image upload request parameters
     Bundle imageParams = new Bundle();
     Bitmap image = BitmapFactory.decodeFile(getActivity().getIntent().getStringExtra("image_for_facebook"));

     // Set up the image upload request callback
     Request.Callback imageCallback = new Request.Callback() {

         @Override
         public void onCompleted(Response response) {
             // Log any response error
             FacebookRequestError error = response.getError();
             if (error != null) {
                 dismissProgressDialog();
                 Log.i(TAG, error.getErrorMessage());
             }
         }
     };
     // Create the request for the image upload
     Request imageRequest = Request.newUploadStagingResourceWithImageRequest(Session.getActiveSession(),
     image, imageCallback);

     // Set the batch name so you can refer to the result
     // in the follow-on object creation request
     imageRequest.setBatchEntryName("imageUpload");


     // Add the request to the batch
     requestBatch.add(imageRequest);

这是随后为图形对象提供其属性的位:

 // Set up the OpenGraphObject representing the book.
    OpenGraphObject book = OpenGraphObject.Factory.createForPost("books.book");
    // Set up the book image; if we uploaded the image, it is the "uri" result from the previous
    // batch request, otherwise it is just a URL.
    String imageUrl = "{result=imageUpload:$.uri}";

    book.setImageUrls(Arrays.asList(imageUrl));

    book.setTitle("A Game of Thrones");
    book.setUrl("https://facemash.biz/books/a_game_of_thrones/");
    book.setDescription("In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.");
    // books.book-specific properties go under "data"
    book.getData().setProperty("isbn", "0-553-57340-3");

我需要做什么才能将此处显示的图像的“user_generated”参数设置为 true?(当然假设我认为这就是获得大图像而不是缩略图所要做的一切是正确的)。

谢谢!

4

2 回答 2

2

查看 Scrumptious 示例,在 SelectionFragment.java 中的 getImageObject 方法。基本上,您需要使用“url”和“user_generated”属性创建一个图形对象:

    GraphObject imageObject = GraphObject.Factory.create();
    imageObject.setProperty("url", "{result=imageUpload:$.uri}");
    imageObject.setProperty("user_generated", "true");
    GraphObjectList<GraphObject> images = GraphObject.Factory.createList(GraphObject.class);
    images.add(imageObject);
    book.setImage(images);
于 2013-11-13T18:38:11.143 回答
0

明的回答对我来说非常接近。为了将图像附加到OpenGraphAction,我必须执行以下操作:

GraphObject imageObject = GraphObject.Factory.create();
imageObject.setProperty("url", imageUrl);
imageObject.setProperty("user_generated", true);
List<JSONObject> images = new ArrayList<JSONObject>();
images.add(imageObject.getInnerJSONObject());
action.setImage(images);

Open Graph Actions 有方法setImage(List<JSONObject> images),但我找不到setImage(GraphObjectList<GraphObject>)方法。我正在使用 Facebook SDK v3.6,所以可能已经改变了。

于 2014-02-12T01:42:02.433 回答