facebook-sdk-for-unity
facebook-sdk-for-unity copied to clipboard
ArgumentException when use FB.API in Unity 2021.1
Checklist
- [x] I've updated to the latest released version of the SDK
- [x] I've searched for existing GitHub issues
- [x] I've looked for existing answers on Stack Overflow, the Facebook Developer Community Forum and the Facebook Developers Group
- [x] I've read the Code of Conduct
- [x] This issue is not security related and can safely be disclosed publicly on GitHub
Environment
Describe your dev environment here, giving as many details as possible. If you have them, make sure to include:
- Unity Editor Version:
2021.1.0f1
- Unity SDK Version:
9.0
- Installation Platform & Verison: All platforms
Goals
I try to use FB.API to query user picture with GET request.
Expected Results
OnResult callback should be invoked in any case (success or error).
Actual Results
OnResult callback is never invoked.
Stack trace:
ArgumentException: Cannot create a data handler without payload data
UnityEngine.Networking.UploadHandlerRaw..ctor (System.Byte[] data) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/UploadHandler/UploadHandler.bindings.cs:97)
UnityEngine.WWW..ctor (System.String url, System.Byte[] postData, System.Collections.Generic.Dictionary`2[TKey,TValue] headers) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequestWWW/Public/WWW.cs:106)
Facebook.Unity.AsyncRequestString+<Start>d__9.MoveNext () (at <a252100d18af4907bfe50f230228e75e>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
Steps to Reproduce
- Initialize Facebook SDK.
- Call API
Code Samples & Details
FB.API($"{_userId}/picture?type=normal", HttpMethod.GET, OnResult);
The issue is caused by legacy WWW
class in Unity 2021. Upgrade to UnityWebRequest
fixes the problem.
Same.
How can I upgrade to UnityWebRequest?
@JustKoTMurchik, you need to patch AsyncRequestString.Start()
method and GraphResult
class.
I'll try to create pull request soon.
@Velorth Thx!
+1
+1
+1
+1
Any update?
Any fix?... Nothing mentioned from the ChangeLog.. :(
- https://developers.facebook.com/docs/unity/change-log
@JustKoTMurchik, you need to patch
AsyncRequestString.Start()
method andGraphResult
class. I'll try to create pull request soon.
What do You mean with "patch"? I would assume i need to compile some DLLs. Is that correct? I tried downloading develop branch, resolve dependency issues, build and replace every DLL of the SDK in my project. but didn't worked.
@Velorth I have tried to build both your forked dev branch and facebook-sdk-for-unity dev branch with your changes. Both build failed.
Have you ever build your dev branch successfully?
@Velorth I have tried to build both your forked dev branch and facebook-sdk-for-unity dev branch with your changes. Both build failed.
Have you ever build your dev branch successfully?
I got success building them. THey just need some nuget references.
Every thing build fine here. But once i try to put the DLLs on my unit project there is no FB.Mobile.something in FB.Mobile. SO not sure what is happening.
@Velorth I have tried to build both your forked dev branch and facebook-sdk-for-unity dev branch with your changes. Both build failed.
Have you ever build your dev branch successfully?
I'm new to GitHub. What we can make for this to make a release ASAP?
@farahjr, dev branch looks a little bit outdated and it is not compatible with examples in master branch. So there isn't any public class in FB.Mobile and Graph API version is set to unsupported v3.0. These changes should be applied to master branch, but according to the rules pullrequests should be made to dev branch.
Replace the code that has been done in https://github.com/facebook/facebook-sdk-for-unity/pull/539/files and compile the projet "Facebook.Unity"
Then replace the DLL in your Unity projet. It works.
Contact me if you want the DLL. I just built it right now using Unity 2021.1.5 DLLs and the login worked again. Tested in Editor and Android. I don't know for IOS.
It is just a workaround until they do it.
With the help of @visualbruno, I have fixed the problem.
Facebook SDK team please fix this bug when you have time because this bug makes your SDK unusable with Unity 2021
With the help of @visualbruno, I have fixed the problem.
Facebook SDK team please fix this bug when you have time because this bug makes your SDK unusable with Unity 2021
Yes please I am waiting also 🙏🙏
The pull request that @Velorth created breaks the support for Unity less than 2017.1 .. that is bad because according to Facebook Unity SDK page they mention that it Requires Unity 5.4 and up. It will not work with version 5.4 - 5.6 and 2017.1
If Facebook still wants to support 5.4 they can't accept that pull request unchanged.
@snorrsi The backward compatibility problem that you mentioned is easy to fix with Platform dependent compilation directives.
Starting from Unity 5.3.4, you can compile code selectively based on the earliest version of Unity required to compile or execute a given portion of code. Given the same version format as above (X.Y.Z), Unity exposes one global #define in the format UNITY_X_Y_OR_NEWER, that can be used for this purpose.
@farahjr, dev branch looks a little bit outdated and it is not compatible with examples in master branch. So there isn't any public class in FB.Mobile and Graph API version is set to unsupported v3.0. These changes should be applied to master branch, but according to the rules pullrequests should be made to dev branch.
That might explain my current problem. I got success integrating with Firebase and facebook at Editor runtime, but when building and deplying on my phone, i Got an oauth error:
2021/05/06 10:23:52.243 16976 21572 Error GraphResponse {HttpStatus: 400, errorCode: 200, subErrorCode: -1, errorType: OAuthException, errorMessage: An access token is required to request this resource.}
I will try fetching master and patching only the changes withing this commit.
@kerembaydogan, conditional compilation is not an option because there are lots of users that use Facebook SDK as a pre-built binary package. According to the Unity docs UnityWebRequest was introduced in Unity 5.4. I will check if it realy works and what can we do if it doesn't.
@Velorth Yeah you are right, that wont work if they continue to release single sdk package.
Maybe they build/release multiple sdk packages from the same code base using directives and support both old and new unity versions?
BTW when unity removes UnityWebRequest they have to find a way.
To get it working, I deleted the Facebook.Unity.dll file and replaced it by the Facebook.Unity source folder then corrected the errors in the C# code. As usual thanks Facebook for never testing Unity SDKs ...
Facebook.Unity
Could you tell a bit more where you found the new facebook.Unity.dll file ? or what do you mean by "replaced it by the Facebook.Unity source folder"? ... I am having the same issue for weeks... :(
Facebook.Unity
Could you tell a bit more where you found the new facebook.Unity.dll file ? or what do you mean by "replaced it by the Facebook.Unity source folder"? ... I am having the same issue for weeks... :(
Hi @samavan, In the FacebookSDK/Plugins folder, I just deleted the Facebook.Unity.dll file, then dropped the folder highlighted on your screenshot in that folder.
Hi @samavan, In the FacebookSDK/Plugins folder, I just deleted the Facebook.Unity.dll file, then dropped the folder highlighted on your screenshot in that folder.
Hmm what I did but getting errors...
Also the Facebook menu disappeared... :(
Finally managed to get the scripts to compile without error removing other dll replacing with the original directories.
However build compilation error on iOS platform.
Sorry I forgot a step, you have to create an assembly definition for Facebook.Unity after adding the folder:
- Right click on Facebook.Unity folder -> Create -> Assembly Definition
- Rename it Facebook.Unity It should work
Sorry I forgot a step, you have to create an assembly definition for Facebook.Unity after adding the folder:
- Right click on Facebook.Unity folder -> Create -> Assembly Definition
- Rename it Facebook.Unity It should work
Thanks! Worked a charm! Project compiles fine :)
And then also project builds fine after re-opening every single scenes from the Examples directory as mentioned the error logs here : https://github.com/facebook/facebook-sdk-for-unity/issues/552
However after compiling on device :
- press FB.Init
- press Classic Login
- press Graph Request
- press Basic request - Me >> give error log from Xcode as below
Any idea? O_o...
Did you replace WWW by UnityWebRequest ? You can find what to change here: https://github.com/facebook/facebook-sdk-for-unity/pull/539/files thanks to @Velorth
However after compiling on device :
- press FB.Init
- press Classic Login
- press Graph Request
- press Basic request - Me >> give error log from Xcode as below
![]()
Any idea? O_o...
Just open the file above and apply the changes. Then recompile, get the dll and replace over your project..
@binouze @farahjr now working a charm, thanks for the fast support! ;)
Replace the code that has been done in https://github.com/facebook/facebook-sdk-for-unity/pull/539/files and compile the projet "Facebook.Unity"
Then replace the DLL in your Unity projet. It works.
Contact me if you want the DLL. I just built it right now using Unity 2021.1.5 DLLs and the login worked again. Tested in Editor and Android. I don't know for IOS.
It is just a workaround until they do it.
Hi i need DLL. Please share it
Hi
You can download them here : https://www.dropbox.com/sh/rh1r4vbevpcmq55/AAAlqW7biGD0fMQUhNzXI1B3a?dl=0 I compiled them using Unity 2021.1.5.
Regards Bruno
Provenance : Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows 10
De : Indra Kumar @.> Envoyé le :lundi, 17 mai 2021 17:29 À : @.> Cc : Bruno @.>; @.> Objet :Re: [facebook/facebook-sdk-for-unity] ArgumentException when use FB.API in Unity 2021.1 (#537)
Replace the code that has been done in https://github.com/facebook/facebook-sdk-for-unity/pull/539/files and compile the projet "Facebook.Unity"
Then replace the DLL in your Unity projet. It works.
Contact me if you want the DLL. I just built it right now using Unity 2021.1.5 DLLs and the login worked again. Tested in Editor and Android. I don't know for IOS.
It is just a workaround until they do it.
Hi i need DLL. Please share it
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/facebook/facebook-sdk-for-unity/issues/537#issuecomment-842419463, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAC7CQHYS6INJVZWF3ZW5MDTOEY7HANCNFSM4ZZTHDZQ.
Hi You can download them here : https://www.dropbox.com/sh/rh1r4vbevpcmq55/AAAlqW7biGD0fMQUhNzXI1B3a?dl=0 I compiled them using Unity 2021.1.5. Regards Bruno Provenance : Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows 10 De : Indra Kumar @.> Envoyé le :lundi, 17 mai 2021 17:29 À : @.> Cc : Bruno @.>; @.> Objet :Re: [facebook/facebook-sdk-for-unity] ArgumentException when use FB.API in Unity 2021.1 (#537) Replace the code that has been done in https://github.com/facebook/facebook-sdk-for-unity/pull/539/files and compile the projet "Facebook.Unity" Then replace the DLL in your Unity projet. It works. Contact me if you want the DLL. I just built it right now using Unity 2021.1.5 DLLs and the login worked again. Tested in Editor and Android. I don't know for IOS. It is just a workaround until they do it. Hi i need DLL. Please share it — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#537 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAC7CQHYS6INJVZWF3ZW5MDTOEY7HANCNFSM4ZZTHDZQ.
Thank you working fine!
Hi You can download them here : https://www.dropbox.com/sh/rh1r4vbevpcmq55/AAAlqW7biGD0fMQUhNzXI1B3a?dl=0 I compiled them using Unity 2021.1.5. Regards Bruno Provenance : Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows 10 De : Indra Kumar @.> Envoyé le :lundi, 17 mai 2021 17:29 À : @.> Cc : Bruno @.>; @.> Objet :Re: [facebook/facebook-sdk-for-unity] ArgumentException when use FB.API in Unity 2021.1 (#537) Replace the code that has been done in https://github.com/facebook/facebook-sdk-for-unity/pull/539/files and compile the projet "Facebook.Unity" Then replace the DLL in your Unity projet. It works. Contact me if you want the DLL. I just built it right now using Unity 2021.1.5 DLLs and the login worked again. Tested in Editor and Android. I don't know for IOS. It is just a workaround until they do it. Hi i need DLL. Please share it — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#537 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAC7CQHYS6INJVZWF3ZW5MDTOEY7HANCNFSM4ZZTHDZQ.
Thanks its Working Fine :)
Thanks, it solved my issue with FB sign-in, but share function doesn't return anything (just FacebookDelegate isn't called). Anyone with the same?
New version of Facebook SDK for Unity released just a few days ago (v11.0.0) and the issue hasn't been solved. Tested with Unity 2021.1.11f1.
I built the DLLs for Facebook SDK v11.0 @pacolaf You can download them here: https://www.dropbox.com/sh/rh1r4vbevpcmq55/AAAlqW7biGD0fMQUhNzXI1B3a?dl=0 I don't use "share" function. Can you test it again @wingsmight ?
I built the DLLs for Facebook SDK v11.0 @pacolaf You can download them here: https://www.dropbox.com/sh/rh1r4vbevpcmq55/AAAlqW7biGD0fMQUhNzXI1B3a?dl=0 I don't use "share" function. Can you test it again @wingsmight ?
Thanks for new dll, but that didn't solve problem with "share" function unfortunately. Callback ShareResult is always Cancelled
I built the DLLs for Facebook SDK v11.0 @pacolaf You can download them here: https://www.dropbox.com/sh/rh1r4vbevpcmq55/AAAlqW7biGD0fMQUhNzXI1B3a?dl=0 I don't use "share" function. Can you test it again @wingsmight ?
Thank you! It solves the login problem. I don't use the "share" function either, so I cannot test it.
Hi @wingsmight FB.ShareLink works for me. Did you install first the SDK from Facebook and then overwrite just the DLLs I shared ?
Hi @wingsmight
FB.ShareLink works for me.
Did you install first the SDK from Facebook and then overwrite just the DLLs I shared ?
Hey, yeah, I did exactly what you wrote, but ShareLink returns right value only on Android. On iOS FB always returns cancelled.
@wingsmight Someone created an issue about this bug: https://github.com/facebook/facebook-sdk-for-unity/issues/553
wow, amazing nobody not only tested the sdk at Facebook but also that the fix didn't make it into the last update. You can tell how seriously fb is taking unity XD
It seems that the bug is solved, not by Facebook but by Unity. Facebook SDK for Unity v11.0.0 (original) finally working on Unity 2021.1.15f1, at least with my app. Can anybody confirm this?
EDIT: Also working with Facebook SDK v9.0.0.
It seems that the bug is solved, not by Facebook but by Unity. Facebook SDK for Unity v11.0.0 (original) finally working on Unity 2021.1.15f1, at least with my app. Can anybody confirm this?
EDIT: Also working with Facebook SDK v9.0.0.
Well spotted @pacolaf .
I haven’t tested this myself but when reading through Unity 2021.1.15 release notes it lists fix for UploadHandlerRaw now accepting null values in Post request. See https://issuetracker.unity3d.com/issues/uploadhandlerraw-throws-argumentexception-when-a-null-gets-passed-as-the-postdata-parameter-to-the-www-contsructor
I suspect the issue of getting user image from FB.Api was using null in parameter for the UploadHandlerRaw method which makes FB SDK now finally usable with 2021.1.15+