1

Using app access token had previously been asked in this question (How to use Facebook appAccessToken with Spring Social) and Craig Walls gave a good explanation why the spring-social API should be user-based for most cases.

I have a scenario, however where I would like our server-side application to make a couple of queries that should not require user-specific permissions. I picked a random public page for examples below

I would like to:

When I test these in the Graph API explorer (https://developers.facebook.com/tools/explorer) using an App Access Token they work fine. App Access Token is obtained by hitting https://graph.facebook.com/v2.0/oauth/access_token?client_id={app-id}&client_secret={app-secret}&grant_type=client_credentials and replacing client_id and client_secret with my Facebook client credentials.

Our application would like to have the ability to make these for any given name so we can make queries about a company's presence.

We will have similar requirements for Twitter, LinkedIn and others so I just wanted to check if there are any means to do this in the current API or whether it will not suit our requirements.

Community
  • 1
  • 1
Matt Byrne
  • 4,908
  • 3
  • 35
  • 52

2 Answers2

2

You do not need to fetch an app access token - you can actually use the app id and secret separated by "|" as the access token. - You can see it at the bottom of the app access token section in the documentation: https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens

Piotr
  • 4,813
  • 7
  • 35
  • 46
  • How would you use this with spring social? If you have an example, that would be great. – Memin Oct 06 '17 at 00:43
1

Spring Social's Facebook API binding does not (yet) support v2.0, but that's something I'm working on right now...so hopefully soon. Once that's complete, there'll certainly be some operations that work only with user access tokens and some that only work with app access tokens, and some that will work with either (FWIW, Twitter's API has a similar set of circumstances).

Keep an eye on the project in GitHub or follow @SpringSocial on Twitter to know when the v2.0 stuff is available. (I'd appreciate any help I can get in testing it.)

Although it makes no sense at all to obtain your FacebookTemplate via the connection framework for app token requests (connections are, by nature, a user-oriented concept), you can always construct a FacebookTemplate wherever you need it, giving it an app access token obtained via OAuth2Template's authenticateClient(). You can certainly do that now with the v1.0 API binding, but I'm uncertain what ops an app token would work with.

FWIW, as I'm working on the v2.0 API binding, I'm starting to sense an opportunity for FacebookTemplate to carry two tokens: A user token and an app token. This way you can perform app-centric requests even from a FacebookTemplate obtained from the connection framework. Then the only time you'd ever want to construct a FacebookTemplate manually is if there are some operations for which either kind of token will work, but the results would be different depending on what type of token is used.

Craig Walls
  • 2,080
  • 1
  • 12
  • 13
  • Thanks for the info, Craig. Will certainly keep an eye on the project and try to help out with testing the new version. I was thinking of even using `RestTemplate` in the mean time and using your classes for the response binding, but that was assuming it was all v2.0. I'll check if there are differences in the v2.0 responses I'm concerned with. The project I'm looking at may not have much maintenance budget so don't want to leave it with an API version that will end of life next year when I won't be around ;-) – Matt Byrne Jun 18 '14 at 20:13
  • At the moment, I have converted all of the API binding except for FeedTemplate. Also, even though it all works, many of the domain types need to be reviewed to be sure that they match up with what v2.0 offers. That is something I *hope* to have finished today or early next week. Once I have it all done, it'll be in a snapshot build ready for review. – Craig Walls Jun 20 '14 at 16:07
  • Thanks for the update Craig - sounds great. I'll keep an eye on the github repo. – Matt Byrne Jun 22 '14 at 21:08
  • 1
    Just a quick followup: Last week I cut Spring Social Facebook 2.0.0.M1 including the v2.0 API binding update. Make sure you have Spring's milestone repo (http://repo.spring.io/milestone/) in your build and then use "org.springframework.social:spring-social-facebook:2.0.0.M1" as the dependency (represented here as Gradle coordinates...adjust accordingly for Maven or other build tools). – Craig Walls Jul 08 '14 at 16:00
  • Thanks Craig - I finally got a chance to use this Milestone and try a few things out. I've found a bug that I raised here: https://jira.spring.io/browse/SOCIALFB-153. – Matt Byrne Jul 15 '14 at 00:09
  • Unrelated to the original question but related to the statement "the only time you'd ever want to construct a FacebookTemplate manually is...", I just encountered another scenario: creating a photo album for a Facebook Page requires the page token, even if you have a user token with "manage_pages" it will not allow the POST to {page}/albums. – Alex Nov 08 '14 at 21:27
  • Any news regarding this? I´ve checked the new v2 release and I can´t any easy way of using FacebookTemplate with just the appId and appSecret... – Piotr Aug 17 '15 at 22:10