Jasper Blues
Jasper Blues

Reputation: 28776

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:

Upvotes: 2

Views: 684

Answers (2)

otmek
otmek

Reputation: 11

After facebook API change, field "first_name" was replaced by field : "name"

public FacebookUser getFacebookUserData() {
    Facebook facebook = new FacebookTemplate(accessToken);
    String[] fields = {"id", "name", "email"};
    FacebookUser user = facebook.fetchObject("me", FacebookUser.class, fields);
    return user;
}

where FacebookUser is :

public class FacebookUser {

String id;
String name;
String email;

public FacebookUser(){ }

public FacebookUser(String id, String name, String email) {
    this.id = id;
    this.name = name;
    this.email = email;
}

Upvotes: 1

Jasper Blues
Jasper Blues

Reputation: 28776

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");

Upvotes: 2

Related Questions