1

i am using the following code to login with facebook callback url got invoked and i got the access code but when i try to get the access token following exception is thrown

 java.lang.IllegalArgumentException: Was expecting a query string of the form 'access_token=XXX' or 'access_token=XXX&expires=YYY'. Instead, the query string was '{"access_token":"sometoken","token_type":"bearer","expires_in":5183998}' 

here is the code

def callBackUrl(code: String) = Action.async { implicit request =>
    log.debug("call back info called")
    log.debug("authorication code is : {} " + code)
    val config = ConfigFactory.load()
    val FBAppId = config.getString("fb.app.id")
    val FBAppSecret = config.getString("fb.app.secretkey")
    val redirectUrl = config.getString("fb.app.callback")
    val scopeBuilder = new ScopeBuilder();
    scopeBuilder.addPermission(UserDataPermissions.USER_LIKES).addPermission(UserDataPermissions.USER_LIKES)
    val wr = new DefaultWebRequestor();
    val accessTokenResponse = wr.executeGet(
      "https://graph.facebook.com/oauth/access_token?client_id=" + FBAppId
        + "&redirect_uri=" + redirectUrl
        + "&client_secret=" + FBAppSecret + "&code=" + code + "&scope=" + scopeBuilder.toString());
    log.debug("got response body for access token {}",accessTokenResponse.getBody)
    val token = AccessToken.fromQueryString(accessTokenResponse.getBody)
    val fbCLient = new DefaultFacebookClient(token.getAccessToken)
    val fbuser = fbCLient.fetchObject("me", classOf[User], Parameter.`with`("fields", "id,name,email, first_name , last_name"))
    log.info("id is : {} ", fbuser.getId)
    log.info("name :"+ fbuser.getName+"User firstname: "+ fbuser.getFirstName+"User lastname: "+ fbuser.getLastName+"User Email:"+ fbuser.getEmail+"User interested in:"+ fbuser.getInterestedIn)
}

i am getting the exception on this line

val token = AccessToken.fromQueryString(accessTokenResponse.getBody)

please help where i am making mistake i am using rest api

swaheed
  • 3,671
  • 10
  • 42
  • 103
  • http://stackoverflow.com/questions/42994019/facebook-graph-api-not-work-from-2-2-to-2-3 – CBroe Apr 13 '17 at 09:20
  • Go look for an updated version of the package/SDK you are using. – CBroe Apr 13 '17 at 09:20
  • Seems like a Content-Type mismatch. "Instead, the query string was ...." tells you you are providing `application/json`, while the API expects `application/x-www-form-urlencoded`. Did you set the Content-Type correctly? Because if the Content-Type isn't set at all the API has to guess the contents, and it could default to `application/x-www-form-urlencoded` while your body content contains `application/json`. – 3limin4t0r Apr 13 '17 at 09:22

0 Answers0