using Facebook.Unity; public void FacebookLogin() { FB.LogInWithReadPermissions(permissions: new List() { "public_profile", "email" }, callback: OnLoginComplete); } private void OnLoginComplete(ILoginResult result) { if (result.Cancelled) { Debug.Log("User cancelled login"); } else if (result.Error != null) { Debug.LogError(result.Error); } else { Debug.Log("User logged in"); } }
using Facebook.Unity; public void GetUserInfo() { FB.API("/me?fields=name,email,picture", HttpMethod.GET, OnUserInfoComplete); } private void OnUserInfoComplete(IGraphResult result) { if (result.Error != null) { Debug.LogError(result.Error); } else { string name = result.ResultDictionary["name"].ToString(); string email = result.ResultDictionary["email"].ToString(); string pictureUrl = result.ResultDictionary["picture"]["data"]["url"].ToString(); Debug.Log($"User: {name}, Email: {email}, Picture: {pictureUrl}"); } }In this example, we call FB.API method with /me endpoint and fields parameter to get user information. We pass an instance of OnUserInfoComplete method as a callback. OnUserInfoComplete method receives IGraphResult as a parameter, checks if an error occurred, and logs the user name, email, and picture URL. Package library: Facebook.Unity.