private String token ( final String home , final String code ) throws IOException { final String response = this . request . uri ( ) . set ( URI . create ( new Href ( PsFacebook . ACCESS_TOKEN_URL ) . with ( PsFacebook . CLIENT_ID , this . app ) . with ( "redirect_uri" , home ) . with ( PsFacebook . CLIENT_SECRET , this . key ) . with ( PsFacebook . CODE , code ) . toString ( ) ) ) . back ( ) . fetch ( ) . as ( RestResponse . class ) . assertStatus ( HttpURLConnection . HTTP_OK ) . body ( ) ; final String [ ] sectors = response . split ( "&" ) ; for ( final String sector : sectors ) { final String [ ] pair = sector . split ( "=" ) ; if ( pair . length != 2 ) { throw new IllegalArgumentException ( String . format ( "Invalid response: '%s'" , response ) ) ; } if ( "access_token" . equals ( pair [ 0 ] ) ) { return pair [ 1 ] ; } } throw new IllegalArgumentException ( String . format ( "Access token not found in response: '%s'" , response ) ) ; }
Retrieve Facebook access token .