Ivan
Ivan

Reputation: 6608

Posting to facebook fan page and to the user's wall in the same time. Android

I have my android application allowing user to share interesting fragments of some texts on the Facebook.

Sharing on the user's wall works fine and is implemented using this tutorial: http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/

I also have a facebook fan page of my application and I would like to consolidate all such individual shares on that page. So that when some user shares text on their wall the program would also publish this on facebook fan page, so that if someone is interested in the discussion they could like the fan page and subscribe to all the comments other users make.

My problem is that I can either publish on user's wall or publish on fan page. How can I do both at the same time?

public void postToWall(){
    Bundle parameters = new Bundle();
        parameters.putString("message", this.messageToPost);
        parameters.putString("description", this.messageDesc);
        parameters.putString("link", this.messageLink);
 // parameters.putString("target_id", FAN_PAGE_ID);

        try {
                facebook.request("me");
             //   String response = facebook.request("me/feed", parameters, "POST");
                String response = facebook.request(FAN_PAGE_ID+"/feed", parameters, "POST");
                Log.d("Tests", "got response: " + response);
                if (response == null || response.equals("") ||
                response.equals("false")) {
                    showToast("Blank response.");
        }
        else {
            showToast("Message posted to your facebook wall!");
        }
        finish();
    } catch (Exception e) {
        showToast("Failed to post to wall!");
        e.printStackTrace();
        finish();
    }
}

This line publishes to user's wall

    String response = facebook.request("me/feed", parameters, "POST");

And this one to fans page

            String response = facebook.request(FAN_PAGE_ID+"/feed", parameters, "POST");

I have set up permissions for my app to publish on the fan page using this post Simple example to post to a Facebook fan page via PHP?

Upvotes: 0

Views: 1419

Answers (1)

MrBubbles
MrBubbles

Reputation: 11

I had the same issue and I just did the requests via two asyncfacebookrunner classes. So basically they are happening in parallel.

private AsyncFacebookRunner mAsyncFbRunner; 
private AsyncFacebookRunner mAsyncFbRunner2;

public void postToWall() {

    boolean success = true;

    Bundle params = new Bundle();

    //this is for posting on the walls

    parameters.putString("message", this.messageToPost);
    parameters.putString("description", this.messageDesc);
    parameters.putString("link", this.messageLink);

    mAsyncFbRunner.request("me/feed", params,"POST", new WallPostListener(), success);
    mAsyncFbRunner2.request(FAN_PAGE_ID+/"feed", params,"POST", new WallPostListener(), success);

}

Upvotes: 1

Related Questions