I have used open graph to share content in may android app it is working but it only post on users time line not on wall, so what should I do to post directly on wall
I have used following function to share
private void publishStory()
{
// Un-comment the line below to turn on debugging of requests
//Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);
Session session = Session.getActiveSession();
if (session != null) {
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
// Show a progress dialog because the batch request could take a while.
progressDialog = ProgressDialog.show(CompleteStatistics.this, "","Please wait", true);
try {
// Create a batch request, firstly to post a new object and
// secondly to publish the action with the new object's id.
RequestBatch requestBatch = new RequestBatch();
// Request: Staging image upload request
// --------------------------------------------
// If uploading an image, set up the first batch request
// to do this.
if (UPLOAD_IMAGE) {
// Set up image upload request parameters
Bundle imageParams = new Bundle();
imageParams.putParcelable("file", bm);
// Set up the image upload request callback
Request.Callback imageCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
// Log any response error
FacebookRequestError error = response.getError();
if (error != null) {
dismissProgressDialog();
}
}
};
// Create the request for the image upload
Request imageRequest = new Request(Session.getActiveSession(),
"me/staging_resources", imageParams,
HttpMethod.POST, imageCallback);
// Set the batch name so you can refer to the result
// in the follow-on object creation request
imageRequest.setBatchEntryName("imageUpload");
// Add the request to the batch
requestBatch.add(imageRequest);
}
// Request: Object request
// --------------------------------------------
// Set up the JSON representing the book
JSONObject book = new JSONObject();
// Set up the book image
if (UPLOAD_IMAGE) {
// Set the book's image from the "uri" result from
// the previous batch request
book.put("image", "{result=imageUpload:$.uri}");
} else {
// Set the book's image from a URL
book.put("image",
"https://furious-mist-4378.herokuapp.com/books/a_game_of_thrones.png");
}
book.put("title", "A Game of Thrones");
book.put("url",
"https://furious-mist-4378.herokuapp.com/books/a_game_of_thrones/");
book.put("description",
"In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.");
JSONObject data = new JSONObject();
data.put("isbn", "0-553-57340-3");
book.put("data", data);
// Set up object request parameters
Bundle objectParams = new Bundle();
objectParams.putString("object", book.toString());
// Set up the object request callback
Request.Callback objectCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
// Log any response error
FacebookRequestError error = response.getError();
if (error != null) {
dismissProgressDialog();
}
}
};
// Create the request for object creation
Request objectRequest = new Request(Session.getActiveSession(),
"me/objects/books.book", objectParams,
HttpMethod.POST, objectCallback);
// Set the batch name so you can refer to the result
// in the follow-on publish action request
objectRequest.setBatchEntryName("objectCreate");
// Add the request to the batch
requestBatch.add(objectRequest);
// Request: Publish action request
// --------------------------------------------
Bundle actionParams = new Bundle();
// Refer to the "id" in the result from the previous batch request
actionParams.putString("book", "{result=objectCreate:$.id}");
// Turn on the explicit share flag
actionParams.putString("fb:explicitly_shared", "true");
// Set up the action request callback
Request.Callback actionCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
dismissProgressDialog();
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getApplicationContext()
.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_LONG).show();
} else {
String actionId = null;
try {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
actionId = graphResponse.getString("id");
} catch (JSONException e) {
}
Toast.makeText(getApplicationContext()
.getApplicationContext(),
actionId+"Post Id",
Toast.LENGTH_LONG).show();
}
}
};
// Create the publish action request
Request actionRequest = new Request(Session.getActiveSession(),
"me/books.reads", actionParams, HttpMethod.POST,
actionCallback);
// Add the request to the batch
requestBatch.add(actionRequest);
// Execute the batch request
requestBatch.executeAsync();
} catch (JSONException e) {
dismissProgressDialog();
}
}
}
0 comments:
Post a Comment