是否可以从我的Android应用程序共享多张照片和文本到Facebook?

时间:2015-12-10 09:27:03

标签: android facebook facebook-graph-api

我想在我的Android应用中整合Facebook分享。我有多个图像和4个文本要分享。所以我的问题是:

  1. 除了使用Facebook SDK之外,我可以将Intent用于此目的吗?
  2. 我添加了Facebook库,并为Sharing on Android中提到的登录和简单共享做了一个示例。我可以根据我的要求使用它吗?
  3. 代码:

    ShareButton shareButton = (ShareButton) findViewById(R.id.fb_share_button);
    
        ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
                .putString("og:type", "books.book")
                .putString("og:title", "A Game of Thrones")
                .putString(
                        "og:description",
                        "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
                .putString("books:isbn", "0-553-57340-3").build();
    
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.ic_launcher);
        SharePhoto photo = new SharePhoto.Builder().setBitmap(bitmap)
                .setUserGenerated(true).build();
    
        // Create an action
        ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                .setActionType("books.reads").putObject("book", object)
                .putPhoto("image", photo).build();
    
        // Create the content
        ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                .setPreviewPropertyName("book").setAction(action).build();
        ShareDialog.show(MainActivity.this, content);
        shareButton.setShareContent(content);
    

1 个答案:

答案 0 :(得分:0)

对于多张照片,您需要多次添加照片。假设您有3张图片要分享。您需要实现以下代码。



ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("books.reads").putObject("book", object)
            .putPhoto("image", photo)
            .putPhoto("image", photo)
            .putPhoto("image", photo).build();




您可以根据需要使此代码动态化。它可以让我分享多个图像。

SharePhotoContent 中还有一种方法是addPhotos,我使用下面的代码来共享图像。我可以在 addPhotos 方法中提供列表<>



private void publishImage() {
		Bitmap image = BitmapFactory.decodeResource(getResources(),
				R.drawable.ic_launcher);

    //You need to get bitmap from any source.

		SharePhoto photo = new SharePhoto.Builder().setBitmap(image)
				.setCaption("Welcome To Facebook Photo Sharing on steroids!")
				.build();

		SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(
				photo).build();

		ShareApi.share(content, null);
		Toast.makeText(this, "Succsesfully posted on your wall",
				Toast.LENGTH_LONG).show();

	}