Search code examples
javafacebookfacebook-graph-apiscribe

request facebook v2.2 api with scribe for authorization


facebook api v1.0 expires on April 30, 2015: https://developers.facebook.com/docs/apps/changelog

We're using scribe (currently version 1.3.6) to do a login via facebook. We need to update to Facebook api v2.2, or later than v1.0

Does scribe support connection to facebook api v2.2 ?

If i look on the generated url which is sent to the user, v1.0 version: https://www.facebook.com/dialog/oauth?client_id=12345678901&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Findex.facebookoauthconnect%3Aauthorize&scope=email%2Cuser_birthday

If i understand right, i connect to the v2.2 api by including /v2.2/ like the following v2.2 version(?): ...facebook.com/v2.2/dialog/...

Is that correct? At least this works for our scenario.

The URLs to facebook are defined in: org.scribe.builder.api.FacebookApi and are not manipulated later in the code, so that i think scribe supports only v1.0 facebook api. Is that correct?

Is it enough to insert the /v2.2/ into the url by ourself to connect to the v2.2 api?

Kind regards David


Solution

  • Note: I never used Scribe since I have my own library written in-house.

    The OAuth authorization process on Facebook hasn't changed, it's merely the API. Therefore, your request path will not be on /{object}/ (if using Facebook v1.0) but rather appended /v2.2/{object}/.

    Scribe library merely allows you to do OAuth to the service providers easier for you. It does not link to ANY service providers specific API's, so you're free to change the API request path as you wish.

    You will need to refer to the latest Graph API reference doc.

    Example:

    // getting user profile
    OAuthService service = new ServiceBuilder()
                                      .provider(FacebookApi.class)
                                      .apiKey(YOUR_API_KEY)
                                      .apiSecret(YOUR_API_SECRET)
                                      .build();
    OAuthService service = facebookServiceProvider.getService();
    OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v2.2/me"); //See how this link is appended with v2.2 path!!!
    service.signRequest(accessToken, oauthRequest);
    Response oauthResponse = oauthRequest.send();
    System.out.println(oauthResponse.getBody()); 
    

    I suggest learning the upgrading changes from Graph v2.1 to Graph v2.2. You shouldn't worry about authentication process but rather the Graph URL.