2

I am trying to use Spring social to connect to a facebook account, I have injected a FacebookServiceProvider into my serverside class as follows:

<bean class="org.springframework.social.twitter.connect.TwitterServiceProvider">
    <constructor-arg value="${twitter.consumer.key}" />
    <constructor-arg value="${twitter.consumer.secret}" />
</bean>
<bean class="org.springframework.social.facebook.connect.FacebookServiceProvider">
    <constructor-arg value="${facebook.app.id}" />
    <constructor-arg value="${facebook.app.secret}" />
</bean>

in the config, and

@Autowired
private TwitterServiceProvider twitterServiceProvider;
@Autowired
private FacebookServiceProvider facebookServiceProvider;

in the serverside class. I am able to get the TwitterApi from the TwitterServiceProvider because I can get the required accessToken ad accessSecret are provided by twitter

@Value("${twitter.access.token}")
private String twitterAccessToken;
@Value("${twitter.access.secret}")
private String twitterAccessSecret;
....
TwitterApi api = twitterServiceProvider.getApi(twitterAccessToken, twitterAccessSecret);

My question is where do I get the required accessToken to get the FacebookApi from the FacebookServiceProvider.

Maksym Demidas
  • 7,707
  • 1
  • 29
  • 36
Clinton Bosch
  • 2,497
  • 4
  • 32
  • 46
  • Let me give an update, I have managed to create an access token from the facebook developers page, but the problem is that the token is only valid for 1 hour. Given that I want to code the connection credentials into my application, this will obviously not work. I have read that it is possible to create a token that never expires using offline_access, but how do I do this using the facebook developers page? – Clinton Bosch Jul 01 '11 at 10:54

2 Answers2

1

Just query the UserConnection table on userId to get the accessToken or join the table with you own Customer or User Entity class.

user794783
  • 3,619
  • 7
  • 36
  • 58
0

I also tried to get accessToken from FacebookServiceProvider but I'd not do it. But you can get accessToken using the help from http://adobocode.com/2010/12/06/accessing-facebook-using-spring-social/

Rafiq
  • 2,000
  • 2
  • 21
  • 27