How to get the access token to a Facebook page from the link with Spring Social?

270 Views Asked by At

I have to get a management token from a page from the link provided by the user. Until then I have collected the username of the page as a substring from the provided link and request permission from the user as follows:

    public String createFacebookAuthorizationURL(String pagename, Long churchId) {
        FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(facebookAppId, facebookSecret);
        OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
        OAuth2Parameters params = new OAuth2Parameters();
        params.setRedirectUri("https://" + this.hostName + "/api/facebook/" + churchId + "/response"); params.setScope("public_profile,pages_show_list,publish_pages,manage_pages,user_events");

        return oauthOperations.buildAuthorizeUrl(params);
    }
public String createFacebookAccessToken(String code, Long churchId) {
    FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(facebookAppId, facebookSecret);
    AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(code, "https://" + this.hostName + "/api/facebook/" + churchId + "/response", null);
    return  accessGrant.getAccessToken();
}

I have already tested the above method and it works. The problem is that: this method requests a token for access to user pages, I want access to only one page, but I do not know how to put this in the requisitiond and token.

I want use this permissions to post text, links and images in fb pages via my system API...

0

There are 0 best solutions below