facebook / facebook-sdk-for-unity

The facebook sdk for unity.
https://developers.facebook.com/docs/unity
Other
493 stars 257 forks source link

Fetching profile picture results in empty texture2d #705

Open EcoEditor opened 1 year ago

EcoEditor commented 1 year ago

Checklist

Environment

Describe your dev environment here, giving as many details as possible. If you have them, make sure to include:

What do you want to achieve?

I want to be able, using the Facebook SDK in Unity Editor, be able to sign in to my Facebook account, using the access token, and retrieve the profile picture and save it as player picture in the game

I want to be able, using Facebook SDK, to make an iOS build, and when pressing the sing in with facebook button, connect my account and retrieve profile picture and save it as player picture in the game

What do you expect to happen?

I can see the player picture being changed to the profile picture of the facebook user

What actually happened? Can you provide a stack trace?

  1. I've passed the query: "me?fields=id,picture" but the result.Texture returned an empty grey texture.

  2. I've passed the query: "me?fields=id,picture" and using webrequest, and the url returned an error HTTP/1.1 404 not found

What are the steps necessary to reproduce this issue?

This is the code for result.Texutre:

        private void RequestFacebookUserData()
        {
            FB.API("me?fields=id,picture", HttpMethod.GET, HandleProfilePhotoCallback);
        }

        private void HandleProfilePhotoCallback(IGraphResult result)
        {
            if (!string.IsNullOrEmpty(result.Error))
            {
                Debug.Log($"result error is {result.Error};
                return;
            }

            if (result.Texture == null) return;
            var pictureTexture = result.Texture;
            previewTextureImage.texture = pictureTexture;
        }

This is the code for webrequest:

        private void RequestFacebookUserData()
        {
            FB.API("me?fields=id,picture", HttpMethod.GET, HandlePictureCallback);
        }

         private void HandlePictureCallback(IGraphResult result)
          {
            var userProfile = result.ResultDictionary;
            Debug.Log($"Full response {result.RawResult}");
             var pictureData = (userProfile["picture"] as IDictionary<string, object>)["data"] as IDictionary<string, object>;
             var pictureUrl = pictureData["url"] as string;
            StartCoroutine(DownloadProfilePicture(pictureUrl));
         }

        private IEnumerator DownloadProfilePicture(string url)
        {
            using (UnityWebRequest uwr = UnityWebRequest.Get(url))
            {
                yield return uwr.SendWebRequest();

                if (uwr.result != UnityWebRequest.Result.Success)
                {
                    Debug.Log(uwr.error);
                }
                else
                {
                    var text = uwr.downloadHandler.text;
                    Debug.Log(text);
                }
            }
        } 

this is the grey texute: image

More things I've tried: I've tried running the Facebook SDK/Examples/Mobile/GrapthRequest scene, with the LogView scene added to the build settings and this didn't do anything in the Editor - this is the GameView: image

its not possible to request anything. Is this example scene only works in a build? Another details, the App was added to the developers account but is not live. From the iOS build I was able to login with my account, but not see the accounts' picture, like in registered (live) games, from AppStore. Should my app be "Live" and on AppStore, to be able to access the profile picture?

Thanks for any help.

Akash5291 commented 1 year ago

Hello EcoEditor, I'm facing same problem in android and editor as well don't checked in ios yet.

Did you find any solution ?

Gillissie commented 2 months ago

Still happening with SDK 17. Hey Facebook, are you paying attention?