Announcement Announcement Module
Collapse
No announcement yet.
How to get the facebook access token using spring social. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get the facebook access token using spring social.

    Hi,
    I am trying to use spring social's facebook api. I want to authenticate multiple users within application. Once user is authenticated I want to retrieve facebook access token. I want use the FB GraphAPI which needs access token.

    Thanks

  • #2
    This question seems rather basic. Have you tried using Spring Social's ConnectController? ConnectController will handle the authorization for you and result in the access token being stored in a database table. From there you can inject a FacebookTemplate (via it's Facebook interface) where you need it and use the API. You don't need to directly handle the access token.

    If you've not done so already, I recommend that you have a look at the Spring Social Showcase example, which does exactly as I said above. You can find the showcase example at https://github.com/SpringSource/spri...ocial-showcase

    Comment


    • #3
      Thanks for reply
      I already using above example mentioned, there are three users in this application.
      I want to login for multiple facebook users after I login to the application using "habuma" user.
      That is
      1) Login using habuma in the web application.
      2) After login click on facebook button and login for facebook user "user1" and get details
      3) Also login for facebook user "user2" and get details.


      Currently I am not even able to connect from different application users to facebook at same time.
      I log in using habuba in one machine and connect to facebook "user1". Now I log in with "kdonald" user on different browser/Machine and try to connect to facebook "user2", it gives the following error on facebook page.

      Given URL is not allowed by the Application configuration.:
      One or more of the given URLs is not allowed by the App's settings.
      It must match the Website URL or Canvas URL, or the domain must be
      a subdomain of one of the App's domains.


      I checked this error and it is related to facebook apps domain and I am not using facebook app.

      Thanks

      Comment


      • #4
        Let's address the first problem first: You want to have a single local user connect with multiple accounts at Facebook. Technically, that *is* possible with Spring Social, but it takes a bit of work to make it happen. I don't have an example showing it, but if you can give me a little time I can cook up something to show you how it works (honestly, I don't recall the exact details at the moment).

        Even if it's possible, it's not a realistic example. At least if you are abiding by Facebook's rules. Facebook frowns upon one user having many accounts at Facebook. While it's certainly possible for you to setup a 2nd (or 3rd or Nth) account for yourself, it's not allowed (see https://www.facebook.com/legal/terms, section 4, item 2). And if they figure out that you are doing that, then they'll start shutting down those accounts.

        The only other scenarios I can see are (1) your single local user is connecting to multiple Facebook accounts that truly do belong to multiple people or (2) you are wanting to use multiple accounts for marketing purposes and these aren't "people" accounts. In case #1, I'd really need to understand the use case more before I can help you. In case #2, that's also frowned upon by Facebook. Rather than create new accounts, you're supposed to create Pages (see https://www.facebook.com/pages/create/).

        As for your second problem, that error indicates that you're possibly attempting to use a callback URL that is different than what the app is configured for at Facebook. May I assume that this happens at connection/signin time with Facebook?

        Comment


        • #5
          Thanks again!
          I am attaching image of one of the social media software. Here if you see user logged in to the application is able to connect to multiple facebook users. I have similar requirement as part of the bigger application. I believe that it should be possible with the spring social api. Let me know your comments on how to achieve this?

          Attachment

          thanks
          Attached Files

          Comment


          • #6
            I see...so you're trying to recreate HootSuite?

            Again, it is possible to do that (at one time we had a sample that allowed a user to create multiple connections to Twitter, but we cleaned that out). That's why the ConnectionRepository interface has methods like findPrimaryConnection() and findConnections()...because it supports the creation and persistence of multiple connections for a given user to a provider.

            Again, it's been some while since I've written code that exercises that part of Spring Social, but if you can wait a bit, I can try to recreate this later this week.

            If you can't wait, then I *think* the trick only involves taking the user through the ConnectController flow again to create a new connection. The challenge there is that the user has already created a connection for one provider account, so they'll need to signout of the provider before going through the connection flow again. In the case of Twitter, Twitter will offer them a chance to signout and sign in as a different user before completing the connection.

            Facebook's harder though...they will see that the user already has a valid authorization and immediately redirect back to the client. So, the user will have to (in a separate browser window/tab) log out of Facebook before going through the connection flow again.

            FWIW, HootSuite cheats a little and automatically logs the user out of Facebook. I don't know, but I suspect they're using Facebook's JavaScript library and calling FB.logout() before taking the user through the authorization flow. You could try that.

            Comment

            Working...
            X