Announcement Announcement Module
Collapse
No announcement yet.
How to fetch group list from facebook using spring social facebook? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to fetch group list from facebook using spring social facebook?

    I have connected my app with facebook using spring social facebook api. It's working nice. I've tried to fetch all groups using following way

    FacebookTemplate facebookTemplate = new FacebookTemplate();
    List<Group> group = facebookTemplate.fetchConnections("me", "groups", Group.class);

    But it generates the following error message

    org.springframework.social.MissingAuthorizationExc eption: Authorization is required for the operation, but the API binding was created without authorization. org.springframework.social.facebook.api.impl.Faceb ookErrorHandler.handleFacebookError(FacebookErrorH andler.java:95) org.springframework.social.facebook.api.impl.Faceb ookErrorHandler.handleError(FacebookErrorHandler.j ava:60) org.springframework.web.client.RestTemplate.handle ResponseError(RestTemplate.java:486) org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:443) org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:415) org.springframework.web.client.RestTemplate.getFor Object(RestTemplate.java:213) org.springframework.social.facebook.api.impl.Faceb ookTemplate.fetchConnections(FacebookTemplate.java :180) org.springframework.social.facebook.api.impl.Faceb ookTemplate.fetchConnections(FacebookTemplate.java :174) com.horoppa.social.facebook.FacebookFeedController .postUpdate(FacebookFeedController.java:52) sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597)

    It may be required to create FacebookTemplate object using AccessToken for authorization.

    FacebookTemplate facebookTemplate = new FacebookTemplate(AccessToken);

    Please help me, how to get accessToken or how to fetch all groups.

  • #2
    You are correct in your diagnosis: You created FacebookTemplate without specifying an access token. In order to use many of the operations provided by FacebookTemplate, you must have an authorized access token.

    There are several ways to get an authorized access token, but I recommend that you have a look at what Spring Social's ConnectController offers you (all of the details are in the documentation and demonstrated in the samples). It is especially useful if you are building a web application, as it handles all of the browser redirection required by Facebook's authorization flow.

    If you're not building a web application, there are other means by which you can get an access token, but which one you choose largely depends on your application.

    Comment


    • #3
      Thanks for your replay. I have created my app as a maven based spring mvc web application. I am able to fetch group list using Facebook interface instead of FacebookTemplate class in following way

      List<Group> groupList = facebook.fetchConnections("me", "groups", Group.class);

      So it is possible to implement all of the functionality of facebook through spring social without knowing what accessToken is. However, can you tell me what method i should call to get accessToken?

      Thanks again
      Rafiq

      Comment


      • #4
        I may be a bit puzzled by what you've done here...but it appears that you're working with a Facebook object given to you via a Connection (like how it is done in the showcase sample). If so, then you should know that there is still an access token involved, but it was handled for you under the covers. By working with Spring Social's connection framework, you never have to deal with the access token or any of the OAuth2 stuff--the framework handles all of that for you.

        So, since an access token is still involved, you should be able to do anything with Facebook API that the access token is authorized to do.

        What puzzles me a bit more, though is that the Facebook interface doesn't have a fetchConnections() method. That's a lower level method used within FacebookTemplate (typically you'd use the higher-level methods in the interfaces given through Facebook methods). You're welcome to use it as you have, but I'm confused as to how you're using it with the Facebook interface, unless you're casting to FacebookTemplate.

        Also, I just noticed that you're asking for the groups of the current user. I don't believe that the API binding supports this in its higher-level API interfaces. I've created https://jira.springsource.org/browse/SOCIALFB-49 to add it to the API binding. In the meantime, you can still access it through the lower level fetchConnections() method as you've done.

        Comment

        Working...
        X