Results 1 to 3 of 3

Thread: Adding app to Facebook Page

  1. #1
    Join Date
    May 2011
    Posts
    3

    Default Adding app to Facebook Page

    Hi. According to fb docs,
    You can install a profile_tab at the end of the current list of installed tabs for a page by issuing an HTTP POST request to PAGE_ID/tabs with a Page Access Token.
    The only parameter is app_id, a String containing the ID of the application for which to install the tab. This call returns a String containing either true or false, dependind on the result of the operation.

    I didn't find any method to do this in PageOperations, so I created a new one. It looks pretty much like post(String pageId, String message), except for the app_id parameter and the call to graphApi.publish(). The publish() method from GraphAPI checks for the "id" in the map returned by facebook and the post() method does not return anything, so I had to create a new method in GraphAPI to return the full result as a String. I called it add(), and implemented it in FacebookTemplate as follows.
    Code:
    public String add(String objectId, String connectionType, MultiValueMap<String, Object> data) {
    	MultiValueMap<String, Object> requestData = new LinkedMultiValueMap<String, Object>(data);
    	URI uri = URIBuilder.fromUri(GRAPH_API_URL + objectId + "/" + connectionType).build();
    	String response = getRestTemplate().postForObject(uri, requestData, String.class);
    	return response;
    }
    Is this OK or am I reinventing something? My problem is solved, so I'm only asking because if it's OK, I should consider commiting these changes to the project.

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,072

    Default

    The add() method is fine, but I might look further into consolidating the publish/post/add methods to avoid adding yet another method that does essentially the same thing.

    The one thing that stuck out to me is that you never mention passing in the page access token as one of the parameters. If you're doing that, then it should work. If not, then I'd be surprised if it worked. Many page operations (including this one) require the user's page-specific access token which is different from the one that is used for most other operations. To get that, you need to call getPageAccessToken() in PageTemplate. You say it works for you, so I'm guessing you're already doing that. But if not, I thought I'd point it out.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    May 2011
    Posts
    3

    Default

    That's correct. I didn't post the PageTemplate code, but it's almost identical to post(), except for the code in red.

    Code:
    public String addAppTab(String pageId, String appId) {
    	requireAuthorization();
    	String pageAccessToken = getPageAccessToken(pageId);
    	MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    	map.set("app_id", appId);
    	map.set("access_token", pageAccessToken);
    	return graphApi.add(pageId, "tabs", map);
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •