- Home /
Facebook SDK IGraphResult is returning null values in Unity 2017.1.0f3
I have some code which loads the user profile picture from Facebook using the Facebook SDK.
private void GetProfilePicture(string userId)
{
FB.API(userId + "/picture?width=256&height=256", HttpMethod.GET, OnGetProfilePicture);
}
private void OnGetProfilePicture(IGraphResult result)
{
Debug.Log(result.RawResult);
if (result.Error == null) // Success
{
Texture2D texture = result.Texture;
texture.name = "ProfilePicture";
DispatchResponse(SocialServiceResult.SUCCESS, texture);
}
else // Failure
{
DispatchResponse(SocialServiceResult.FAILURE, null);
}
}
The exact same codebase used to work perfectly fine in the previous version of Unity i.e. 5.6.2. I have tested the codebase both on the editor and the device (Android) but the issue remains. Just for reference here is what I get on the editor console on logging failure:
Unable to get the profile picture. SocialServiceResult: FAILURE
UnityEngine.Debug:LogWarning(Object)
TurboLabz.Gamebet.Logger:LogWarning(Object) (at Assets/Common/Scripts/Utils/Static/Logger.cs:39)
TurboLabz.Gamebet.GetPlayerProfilePictureCommand:OnGetProfilePicture(SocialServiceResult,
Texture2D) (at Assets/Gamebet/Scripts/Controllers/GetPlayerProfilePictureCommand.cs:61)
strange.extensions.promise.impl.Promise`2:CallListener() (at Assets/Strange/extensions/promise/impl/Promise.cs:205)
strange.extensions.promise.impl.Promise`2:Dispatch(SocialServiceResult, Texture2D) (at Assets/Strange/extensions/promise/impl/Promise.cs:165)
TurboLabz.Gamebet.FBGetProfilePictureRequest:DispatchResponse(SocialServiceResult, Texture2D) (at Assets/Gamebet/Scripts/Services/Facebook/FBRequests/FBGetProfilePictureRequest.cs:104)
TurboLabz.Gamebet.FBGetProfilePictureRequest:OnGetProfilePicture(IGraphResult) (at Assets/Gamebet/Scripts/Services/Facebook/FBRequests/FBGetProfilePictureRequest.cs:98)
Facebook.Unity.<Start>d__9:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
I also checked the values of the different variables. The value of result.Error
is an empty string; it is not null. The value of result.Texture
is null. On logging the value of result.RawResult
the editor console shows:
����
UnityEngine.Debug:Log(Object)
TurboLabz.Gamebet.Logger:Log(Object) (at Assets/Common/Scripts/Utils/Static/Logger.cs:29)
TurboLabz.Gamebet.FBGetProfilePictureRequest:OnGetProfilePicture(IGraphResult) (at Assets/Gamebet/Scripts/Services/Facebook/FBRequests/FBGetProfilePictureRequest.cs:99)
Facebook.Unity.<Start>c__Iterator0:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
That looks like some garbage value inside result.RawResult
.
Another thing worth mentioning is that I can log into my game perfectly fine with using Facebook SDK; no issues there. It's just the profile picture that has become an issue.
This problem started occurring after upgrading Unity to 2017.1.0f3 (64bit) on the very same codebase that I had earlier. I am running Unity on macOS Sierra. Facebook SDK version is 7.9.4 (I also upgraded to Facebook SDK version 7.10.0 but no luck).
Does anybody have any idea what could be the problem? Or is it a bug in Unity/Facebook SDK?
Thanks in advance.
Answer by Jasr_88 · Jul 28, 2017 at 03:38 AM
Hello, You might make the request this way:
FB.API(userId + "/picture?width=256&height=256&redirect=false"....
This way you'r responce won't be empty, for furter information of how to get the texture of the profile picture, you can see this post
http://answers.unity3d.com/questions/1074298/new-facebook-sdk-fot-unity-70-loading-a-profile-pi.html
i hope you will find this information useful Sorry for the bad english.
Thanks for the answer. This seems like a bug patch to me rather than a proper solution. Adding redirect=false
did indeed return me a response but now it sends the image url ins$$anonymous$$d of the texture itself. This means that I'll have to retrieve the image myself in another call. However, my question really is that why has the texture retrieval stopped working all of a sudden? Is it a bug on Facebook's end? Ideally I would want to use result.Texture
to simply get the image.
Another question: For the response to be error free should I just check result.Error == null
or should I check for string.IsNullOrEmpty(result.Error)
? Can a valid response ever have an empty string error or will it always be null?
So I figured it out for the error. Digging into the Facebook Unity SD$$anonymous$$ source here I found this comment: "If no error occurred value is null or empty." So the right check would be string.IsNullOrEmpty(result.Error)
. Thought this could be of help to others.
Thanks for your info.
Ins$$anonymous$$d of using
if (result.Error != null)
I use if (!string.IsNullOrEmpty(result.Error)) help me fix the error.
Your answer
Follow this Question
Related Questions
Facebook Login - Android 1 Answer
Facebook Android Studio 0 Answers
Facebook SDK(android) - error 1 Answer
Game Analytics & Facebook sdk android build error 1 Answer
D8: Program type already present: com.facebook.unity.Constants 2 Answers