由于FB,我把这个简单的问题弄得很复杂。我尝试使用facebook sdk从android分享链接和图像。 有没有人玩过ShareOpenGraphObject,ShareOpenGraphAction和ShareOpenGraphContent之前,facebook文档很糟糕,没有任何例子。我在等待例子。
由于
答案 0 :(得分:2)
让我们发布一些代码:
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();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("books.reads")
.putObject("book", object)
.putPhoto("image", photo)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("book")
.setAction(action)
.build();
shareDialog.show(this, content);
想法是我不想使用一本书,我只想分享一个图像链接和一条消息......我是怎么做到的? facebook sdk很糟糕
答案 1 :(得分:0)
简单,您可以在Facebook SDK中找到许多示例,您可以找到同样的样本......
Bundle postParams = new Bundle();
postParams.putString("link", url);
postParams.putString("picture", imgUrl);
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
答案 2 :(得分:0)
我认为通过使用facebook sdk 4.0,您可以通过share api分享内容。
例如:
public void share()
{
ShareLinkContent content=new ShareLinkContent.Builder()
.setContentTitle("Your Title")
.setContentUrl(Uri.parse("website link"))
.setImageUrl(Uri.parse("Image url"))
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>(){
@Override
public void onSuccess(Result result){
}
@Override
public void onCancel(){
}
@Override
public void onError(FacebookException error){
}
});
}
答案 3 :(得分:0)
要分享链接和图片, ShareDialog 提供通过Facebook共享对话框和
共享内容的功能<强> ShareLinkContent 强> 描述要共享的链接内容。
是一种没有Open Graph方法的方法。
Snippet就像
private ShareDialog shareDialog;
private boolean canPresentShareDialogWith;
shareDialog = new ShareDialog(this);
canPresentShareDialogWith = ShareDialog.canShow(ShareLinkContent.class);
ShareLinkContent linkContent = new ShareLinkContent.Builder().setContentTitle("Shared from " + "<APP NAME>")
.setContentDescription(
"Question:" + data.getQuestion() + "\n"
// + "Asked by : "
// + data.getName() + "\n"
)
.setContentUrl(
Uri.parse("<Website url>"))
.setImageUrl(Uri.parse(data.getPicUploadPath()))
.build();
if (canPresentShareDialogWith) {
shareDialog.show(linkContent);
} else if (profile != null && hasPublishPermission()) {
ShareApi.share(linkContent, shareCallback);
}
private FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>() {
@Override
public void onCancel() {
Log.d("HelloFacebook", "Canceled");
}
@Override
public void onError(FacebookException error) {
Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
String title = getString(R.string.error);
String alertMessage = error.getMessage();
showResult(title, alertMessage);
}
@Override
public void onSuccess(Sharer.Result result) {
Log.d("HelloFacebook", "Success!");
if (result.getPostId() != null) {
String title = getString(R.string.success);
String id = result.getPostId();
String alertMessage = getString(
R.string.successfully_posted_post, id);
showResult(title, alertMessage);
}
}
private void showResult(String title, String alertMessage) {
new AlertDialog.Builder(NewsfeedMain.this).setTitle(title)
.setMessage(alertMessage)
.setPositiveButton(R.string.ok, null).show();
}
};
这里的方法是与相应的网址共享一个链接,当从FB Feed点击时,图像共享是通过本地Facebook安卓应用程序的链接或回退到sdk共享对话框是没有Facebook应用程序是坚持。