Search code examples
javaioskotlinspring-social-facebook

Spring FacebookTemplate raises permission exception for user profile


I'm having trouble continuing an OAuth session using a token obtained on an iOS client from a back-service. Specifically it looks to be a permission problem:

iOS Client Obtains Access Token (ObjC / FB iOS SDK v3.24)

Session established with the following permissions:

[FBSession openActiveSessionWithReadPermissions:@[
                @"email",
                @"user_about_me",
                @"user_friends",
                @"user_birthday",
                @"public_profile" . . . 

On completion . . .

FBSession *session = [FBSession activeSession];
NSString *accessToken = [session.accessTokenData accessToken];

Access Token Sent to Backend (which is Spring Boot + Kotlin)

A Spring FacebookTemplate is instantiated using the token obtained above, as follows:

@Test fun testFacebookTemplate()
{
    val facebook = FacebookTemplate("$$TOKEN_FROM_FACEBOOK_IOS_SDK$$")

    //Raises exception . . 
    val profile = facebook.userOperations().userProfile 
    println("Profile: " + profile)
}

The OAuth session established on the iOS client is continued from the backend successfully, and eg, a Facebook friend list can be returned. However, attempting to retrieve the profile, as shown above raises an error:

Error from Facebook: {"error":{"message":"(#3) Application does not have the capability to make this API call." , "type":"OAuthException","code":3,"fbtrace_id":"B4C+eS3n2PW"}}
DEBUG o.s.s.f.a.impl.FacebookErrorHandler - Facebook error: 
DEBUG o.s.s.f.a.impl.FacebookErrorHandler -    CODE        : 3
DEBUG o.s.s.f.a.impl.FacebookErrorHandler -    TYPE        : OAuthException

Question:

  • Which permission is missing to return the User object. This does not appear to be documented in Spring's FacebookTemplate
  • Is this requested during OAuth authentication/authorization ( in my case with the FB iOS SDK) or via the developer console? This is unclear to me because both the openActiveSessionWithPermissions and the definition of the application in Facebook's web console contain references to these permissions.

Solution

  • It appears as though Spring's FacebookTemplate v2.0.2.RELEASE has some permission related error when invoking the request for user profile against the Facebook Graph API v2.3

    As a work-around use:

    val profile = facebook.fetchObject("me", User::class.java, 
        "id", "first_name", "last_name", "email");