我正在使用以下代码登录 facebook 回调 url 被调用并且我得到了访问代码但是当我尝试获取访问令牌时抛出异常
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}'
这是代码
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)
}
我在这条线上遇到了异常
val token = AccessToken.fromQueryString(accessTokenResponse.getBody)
请帮助我在哪里犯错我正在使用rest api