facebook-android-sdk icon indicating copy to clipboard operation
facebook-android-sdk copied to clipboard

custom posting story using OpenGraphObject Facebook SDK integration in android

Open achinverma opened this issue 12 years ago • 1 comments

I am using the below code which is working fine to me. It Is posting on User's timeline the story very well. This code posting the story which is : Jarnail Saini read A Game of Thrones on BlurEffect. where jarnail saini is the user and BlurrEffect is the app. but I want to custumise the story.i want to write jarnail saini requested a song "SongName" at "outletname" via BlurEffect. I have spent so much time on it but not able to write the custom text. The below code I have taken from developers site.it is very good and working well.but what changes in have to do in code for posting the text I explain above?

List permissions = session.getPermissions(); if (!isSubsetOf(PERMISSIONS, permissions)) { pendingPublishReauthorization = true; Session.NewPermissionsRequest newPermissionsRequest = new Session .NewPermissionsRequest(MainActivity.this, PERMISSIONS); session.requestNewPublishPermissions(newPermissionsRequest); return; }

// Show a progress dialog because the batch request could take a while. progressDialog = ProgressDialog.show(MainActivity.this, "", getResources().getString(R.string.progress_dialog_text), true);

// Create a batch request RequestBatch requestBatch = new RequestBatch();

// Request: Object request // --------------------------------------------

// Set up the OpenGraphObject representing the book. OpenGraphObject book = OpenGraphObject.Factory.createForPost("books.book");

String imageUrl = "https://furious-mist-4378.herokuapp.com/books/a_game_of_thrones.png"; book.setImageUrls(Arrays.asList(imageUrl)); book.setTitle("A Game of Thrones"); book.setUrl("https://blureffect_unique/books/a_game_of_thrones/"); book.setDescription("In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering."); // books.book-specific properties go under "data" book.getData().setProperty("isbn", "0-553-57340-3");

// Set up the object request callback Request.Callback objectCallback = new Request.Callback() {

@Override
public void onCompleted(Response response) {
    // Log any response error
    Log.i("Responce", ""+response);
    FacebookRequestError error = response.getError();
    if (error != null) {
        dismissProgressDialog();
        Log.i(TAG, error.getErrorMessage());
    }
}

};

// Create the request for object creation Request objectRequest = Request.newPostOpenGraphObjectRequest(Session.getActiveSession(), book, 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);

// TO DO: Add the publish action request to the batch // Request: Publish action request // -------------------------------------------- OpenGraphAction readAction = OpenGraphAction.Factory.createForPost("books.reads"); // Refer to the "id" in the result from the previous batch request // readAction.setProperty("book", "{result=objectCreate:$.id}"); readAction.setProperty("book", "{result=objectCreate:$.id}"); // Turn on the explicit share flag readAction.setExplicitlyShared(true);

// Set up the action request callback Request.Callback actionCallback = new Request.Callback() {

@Override
public void onCompleted(Response response) {
    dismissProgressDialog();
    FacebookRequestError error = response.getError();
    Log.i("Responce2", ""+response);
    if (error != null) {
        Toast.makeText(
                getApplicationContext(),
                error.getErrorMessage(),
                Toast.LENGTH_LONG).show();
    } else {
        String actionId = null;
        try {
            JSONObject graphResponse = response
                    .getGraphObject()
                    .getInnerJSONObject();
            actionId = graphResponse.getString("id");
        } catch (JSONException e) {
            Log.i(TAG,
                    "JSON error "+ e.getMessage());
        }
        Toast.makeText(
                getApplicationContext(),
                actionId,
                Toast.LENGTH_LONG).show();
    }
}

};

// Create the publish action request Request actionRequest = Request.newPostOpenGraphActionRequest(Session.getActiveSession(), readAction, actionCallback);

// Add the request to the batch requestBatch.add(actionRequest); // Execute the batch request requestBatch.executeAsync(); }

achinverma avatar Mar 19 '14 11:03 achinverma

Currently an action and a single object is supported for graph stories: https://developers.facebook.com/docs/opengraph/creating-custom-stories

gcaglar avatar Oct 18 '14 21:10 gcaglar