Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to Limited Login Data for getProfile Method #163

Open
sinanverve7 opened this issue Dec 31, 2024 · 0 comments
Open

Fallback to Limited Login Data for getProfile Method #163

sinanverve7 opened this issue Dec 31, 2024 · 0 comments

Comments

@sinanverve7
Copy link

Is your feature request related to a problem? Please describe.
In iOS 17, the getProfile method is restricted when using Facebook's Limited Login. However, the Limited Login flow still provides access to a significant amount of user profile data through the supported permissions outlined in Facebook's Limited Login documentation.

Currently, developers need to implement custom logic to fetch this data.

Describe the solution you'd like
Enhance the getProfile method to include a fallback mechanism for retrieving user data when the Limited Login flow is detected. This can be achieved by directly using the getUserInfo method to fetch available data without requiring additional Graph API calls. Below is an example implementation of this solution:

@objc func getUserInfo(_ call: CAPPluginCall) {
    guard let userProfile = Profile.current else {
        call.reject("User profile not available. Ensure the user is logged in.")
        return
    }

    // Map user profile fields to a dictionary
    let userProfileData: [String: Any] = [
        "id": userProfile.userID,
        "name": userProfile.name ?? "",
        "firstName": userProfile.firstName ?? "",
        "middleName": userProfile.middleName ?? "",
        "lastName": userProfile.lastName ?? "",
        "email": userProfile.email ?? "",
        "birthday": userProfile.birthday ?? "",
        "gender": userProfile.gender ?? "",
    ]

    // Resolve the call with user profile data
    call.resolve(userProfileData)
}

@objc func getProfile(_ call: CAPPluginCall) {
    // Get the tracking mode (default to "limited")
    let tracking = call.getString("tracking") ?? "limited"

    // Check if tracking is limited
    if tracking == "limited" {
        // Call getUserInfo directly for limited login
        self.getUserInfo(call)
        return
    }

    guard let accessToken = AccessToken.current else {
        call.reject("You're not logged in. Call FacebookLogin.login() first to obtain an access token.")
        return
    }

    if accessToken.isExpired {
        call.reject("AccessToken is expired.")
        return
    }

    guard let fields = call.getArray("fields", String.self) else {
        call.reject("Missing fields argument")
        return
    }
    let parameters = ["fields": fields.joined(separator: ",")]
    let graphRequest = GraphRequest.init(graphPath: "me", parameters: parameters)

    graphRequest.start { (_ connection, _ result, _ error) in
        if error != nil {
            call.reject("An error has occurred.")
            return
        }

        call.resolve(result as! [String: Any])
    }
}


Explanation

  • getUserInfo Method:

    • Retrieves the user profile data directly from the Profile.current object provided by Facebook's Limited Login.
    • Maps the user data (such as id, name, email, birthday, and gender) to a dictionary and resolves the plugin call with this data.
  • Fallback Logic in getProfile:

  • If the tracking parameter is set to "limited", the getProfile method invokes the getUserInfo method to fetch the available user data without relying on an active Graph API request or access token.

  • This ensures that developers can still access the user information available in the Limited Login context, even when getProfile cannot fetch additional data via the Graph API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant