Facebook SDK 4.2 分享图片和文字
Sharing Pictures and Text with Facebook SDK 4.2
我正在尝试使用 Facebook SDK 4.2 共享图片和文本,但是当我调用共享功能(通过 SDK 或 intent)时,我得到的只是一个没有文本的图像。
这是代码
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + mFilepath));
shareIntent.putExtra(Intent.EXTRA_TEXT,"example");
shareIntent.setPackage("com.facebook.katana");
startActivity(shareIntent);
Try this
// By this method we can post on facebook.
private void publishFeedDialog() {
Session session = Session.getActiveSession();
//if(session==null)
{
// try to restore from cache
session = Session.openActiveSessionFromCache(dashBoard);
}
Bundle params = new Bundle();
params.putString("name", "MeetMeUp");
params.putString("caption", "Discover events nearby, easily create events and invite your friends!");
params.putString("description", "Finding, creating and sharing activities you’re passionate about are made easy with MeetMeUp. Whether you’re organizing a small gathering with friends, looking for a neighborhood football game or going to a local music concert, MeetMeUp makes it happen. ");
params.putString("link", "https://play.google.com/store/apps/details?id=com.meetmeup.activity");
params.putString("picture", "http://72.167.41.165/meetmeup/webservices/images/aaaaa-05.jpg");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(),session, params)).setOnCompleteListener(
new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(), "Posted story, id: " + postId, Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(), "Error posting story", Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
请检查以下代码,它可能对您有所帮助。
Bundle parameters = new Bundle();
parameters.putString("message", category_item_name_desc.getText().toString());
parameters.putString("picture", categoryItemsModel.getImageUrl());
parameters.putString("caption", txtDescription_desc.getText().toString());
facebook.request("/me/feed", parameters, "POST");
Facebook 不允许预先填写消息。
有关详细信息,请参阅 this discussion。
我正在尝试使用 Facebook SDK 4.2 共享图片和文本,但是当我调用共享功能(通过 SDK 或 intent)时,我得到的只是一个没有文本的图像。 这是代码
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + mFilepath));
shareIntent.putExtra(Intent.EXTRA_TEXT,"example");
shareIntent.setPackage("com.facebook.katana");
startActivity(shareIntent);
Try this
// By this method we can post on facebook.
private void publishFeedDialog() {
Session session = Session.getActiveSession();
//if(session==null)
{
// try to restore from cache
session = Session.openActiveSessionFromCache(dashBoard);
}
Bundle params = new Bundle();
params.putString("name", "MeetMeUp");
params.putString("caption", "Discover events nearby, easily create events and invite your friends!");
params.putString("description", "Finding, creating and sharing activities you’re passionate about are made easy with MeetMeUp. Whether you’re organizing a small gathering with friends, looking for a neighborhood football game or going to a local music concert, MeetMeUp makes it happen. ");
params.putString("link", "https://play.google.com/store/apps/details?id=com.meetmeup.activity");
params.putString("picture", "http://72.167.41.165/meetmeup/webservices/images/aaaaa-05.jpg");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(),session, params)).setOnCompleteListener(
new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(), "Posted story, id: " + postId, Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(), "Error posting story", Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
请检查以下代码,它可能对您有所帮助。
Bundle parameters = new Bundle();
parameters.putString("message", category_item_name_desc.getText().toString());
parameters.putString("picture", categoryItemsModel.getImageUrl());
parameters.putString("caption", txtDescription_desc.getText().toString());
facebook.request("/me/feed", parameters, "POST");
Facebook 不允许预先填写消息。 有关详细信息,请参阅 this discussion。