Reputation: 4536
i am creating an app for share something to facebook. here when i click on a button the feed dialog box will come for sharing, there is a text box for adding message, my need is that i need to send a data to the text box from my code. how can i send it ??
and this is my code to show the feed dialog box.
private void showFeedDialog() {
Bundle postParams = new Bundle();
postParams.putString("description","message from me ");
postParams.putString("link", "https://www.google.com");
WebDialog feedDialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(),postParams)
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if(error==null)
{
final String postId=values.getString("post_id");
if(postId!=null)
Toast.makeText(getApplicationContext(), "Posted Successfully", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "Post canceled", Toast.LENGTH_SHORT).show();
}
else
if(error instanceof FacebookOperationCanceledException)
Toast.makeText(getApplicationContext(), "Publish canceled",Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "connection error", Toast.LENGTH_SHORT).show();
}
}).build();
feedDialog.show();
}
Upvotes: 0
Views: 5513
Reputation: 1
To post message from activity use this
Bundle postParams = new Bundle();
postParams.putString("message", "your message");
postParams.putString("name", "Facebook SDK 3.0 Test By Arshad");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description",
"The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
postParams.putString("picture",
"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
Upvotes: 0
Reputation: 15662
You cannot specify a user message to the feed dialog. The "name", "caption", and "description" fields only apply to the "link" that's being shared.
This is by design.
Upvotes: 2
Reputation: 11915
The code for Publishing your Feed using the new Facebook SDK 3.0 is as follows:
// Method for publishing a feed to Facebook
private void publishStory() {
Session session = Session.getActiveSession();
Bundle postParams = new Bundle();
postParams.putString("name", "Facebook SDK 3.0 Test By Arshad");
postParams.putString("caption", "Build great social apps and get more installs.");
postParams.putString("description",
"The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
postParams.putString("link", "https://developers.facebook.com/android");
postParams.putString("picture",
"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
Log.i(TAG, "onCompleted FacebookRequest Done");
JSONObject graphResponse = response.getGraphObject()
.getInnerJSONObject();
try {
graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG, "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Log.i(TAG, "FacebookRequestError" + error.getErrorMessage());
Toast.makeText(getActivity().getApplicationContext(),
error.getErrorMessage(), Toast.LENGTH_SHORT).show();
} else {
Log.i(TAG, "FacebookRequest Done");
Toast.makeText(getActivity().getApplicationContext(),
"Story Published to Your Wall", Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
Upvotes: 0