0

Facebook seems to answer some API calls with text/plain instead of application/json. The oauth endpoint https://graph.facebook.com/oauth/access_token is one example. This seems to confuse the vert.x oauth client implementation. This is the call that fails:

oauth2.getToken(new JsonObject()
                        .put("code", code)
                        .put("redirect_uri", callbackUrl),
                res -> {
                    if (res.failed()) {
                       logger.warn(res.cause().getMessage());
                    } else {
                       AccessToken = res.result();
                       // ...etc...
                    }

The logged message is: Cannot handle content type: text/plain

So my question is, apart from the obvious solution of implementing my own getToken() method just for the Facebook provider, is there any other way to make the implementation parse the plain text response? It is a simple url encoded string like access_token=foo&expires=5179336

Is there a way to make Facebook answer in JSON that I am not aware of?

Adam Michalik
  • 9,678
  • 13
  • 71
  • 102
kliron
  • 4,383
  • 4
  • 31
  • 47

1 Answers1

0

Use a newer version of the Facebook API. In v2.3 they changed the format of oauth/access_token to return JSON.

So https://www.facebook.com/v2.3/oauth/access_token and https://www.facebook.com/v2.7/oauth/access_token will return JSON in the format {"access_token": {TOKEN}, "token_type":{TYPE}, "expires_in":{TIME}}.

If you or the SDK you're using is using the uri https://graph.facebook.com/oauth/access_token then it's using the v2.0 API instead of the current version.

Daniel Friesen
  • 337
  • 3
  • 12