我想在我的Android应用程序中集成Facebook共享。我有多张图片和4条文字要分享。所以我的问题是:
- 除了使用Facebook SDK之外,我还可以将Intent用于此目的吗
- 我已经添加了Facebook库,并做了一个登录和简单共享的示例,就像在Android上的共享中提到的那样。我可以使用它来满足我的需求吗
代码:
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);
对于多张照片,您需要多次添加照片。假设你有3张图片可以分享。您需要实现以下代码。
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads").putObject("book", object)
.putPhoto("image", photo)
.putPhoto("image", photo)
.putPhoto("image", photo).build();
您可以根据需要使此代码动态。共享多个图像对我来说很好。
还有一种方法是在SharePhotoContent中添加照片,我使用了下面的代码来共享图像。我能够提供列表<>在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();
}