0
votes

Hello i'm playing with spring boot and learning web services. I started playing with facebook graph api and using restfb. I get the access token and hard code it every time. Now i dont always want to hard code my credentials(access tokens), i want to be able to get the token when i sign in into my account without hard coding the access tokens every time i try to retrieve my photos from face and use it in my application. Has anyone worked with restfb show me an example of how to automatically get the access tokens without hard coding it. Thanks. My uri is just "localhost:8080/myapp."

@Controller
@RequestMapping("/")
public class HomeController {

  @Value("#{faceBookappId['APP_KEY']}")
  private static String APP_KEY;
  @Value("#{faceBookappSecret['SECRET']}")
  private static String APP_SECRET;


 private FacebookClient.AccessToken getFaceBookUserToken(String code, String url) throws IOException {
   WebRequestor web = new DefaultWebRequestor();
   WebRequestor.Response accessTokens = web.executeGet("https://graph.facebook.com/oauth/access_token?client_id="+
   APP_KEY+url+"&client_secret="+APP_SECRET+"&code=" + code);

     return     DefaultFacebookClient.AccessToken.fromQueryString(accessTokens.getBody());
 }

      @RequestMapping(method= RequestMethod.GET)
      public String helloFaceBook(Model model) {

        String url = "https://www.facebook.com/dialog/oauth?"+APP_KEY;
        return "redirect"+url;
    }



}
1

1 Answers

0
votes

You can use the obtainUserAccessToken from the DefaultFacebookClient FacebookClient facebookClient = new DefaultFacebookClient(Version.VERSION_2_2); facebookClient.obtainUserAccessToken(appId, appSecret, redirectUri, verificationCode);