facebook-sdk-for-unity icon indicating copy to clipboard operation
facebook-sdk-for-unity copied to clipboard

ArgumentException when use FB.API in Unity 2021.1

Open Velorth opened this issue 3 years ago • 50 comments

Checklist

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

  1. Initialize Facebook SDK.
  2. Call API

Code Samples & Details

FB.API($"{_userId}/picture?type=normal", HttpMethod.GET, OnResult);

Velorth avatar Mar 25 '21 15:03 Velorth

The issue is caused by legacy WWW class in Unity 2021. Upgrade to UnityWebRequest fixes the problem.

Velorth avatar Mar 29 '21 10:03 Velorth

Same.

How can I upgrade to UnityWebRequest?

byteflowY avatar Mar 29 '21 15:03 byteflowY

@JustKoTMurchik, you need to patch AsyncRequestString.Start() method and GraphResult class. I'll try to create pull request soon.

Velorth avatar Mar 29 '21 15:03 Velorth

@Velorth Thx!

byteflowY avatar Mar 29 '21 15:03 byteflowY

+1

Thaina avatar Apr 02 '21 08:04 Thaina

+1

binouze avatar Apr 13 '21 11:04 binouze

+1

lucas-brasmobi avatar Apr 15 '21 22:04 lucas-brasmobi

+1

alexandrumaneaivfuture avatar Apr 19 '21 12:04 alexandrumaneaivfuture

Any update?

kerembaydogan avatar Apr 23 '21 16:04 kerembaydogan

Any fix?... Nothing mentioned from the ChangeLog.. :(

  • https://developers.facebook.com/docs/unity/change-log

samavan avatar Apr 26 '21 08:04 samavan

@JustKoTMurchik, you need to patch AsyncRequestString.Start() method and GraphResult 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.

farahjr avatar May 04 '21 17:05 farahjr

@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?

kerembaydogan avatar May 04 '21 17:05 kerembaydogan

@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.

farahjr avatar May 04 '21 17:05 farahjr

@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?

image

I'm new to GitHub. What we can make for this to make a release ASAP?

farahjr avatar May 04 '21 17:05 farahjr

@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.

Velorth avatar May 05 '21 05:05 Velorth

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.

visualbruno avatar May 06 '21 11:05 visualbruno

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

kerembaydogan avatar May 06 '21 17:05 kerembaydogan

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 🙏🙏

samavan avatar May 06 '21 18:05 samavan

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 avatar May 06 '21 18:05 snorrsi

@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.

kerembaydogan avatar May 06 '21 18:05 kerembaydogan

@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.

farahjr avatar May 06 '21 19:05 farahjr

@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 avatar May 06 '21 19:05 Velorth

@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.

kerembaydogan avatar May 06 '21 19:05 kerembaydogan

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 ...

binouze avatar May 07 '21 06:05 binouze

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... :(

image

samavan avatar May 09 '21 10:05 samavan

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... :(

image

image

farahjr avatar May 09 '21 15:05 farahjr

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.

binouze avatar May 10 '21 05:05 binouze

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... :( Screen Shot 2564-05-10 at 12 19 03

samavan avatar May 10 '21 05:05 samavan

Screen Shot 2564-05-10 at 12 27 50 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.

samavan avatar May 10 '21 05:05 samavan

Sorry I forgot a step, you have to create an assembly definition for Facebook.Unity after adding the folder:

  1. Right click on Facebook.Unity folder -> Create -> Assembly Definition
  2. Rename it Facebook.Unity It should work

Screenshot 2021-05-10 100808

binouze avatar May 10 '21 06:05 binouze

Sorry I forgot a step, you have to create an assembly definition for Facebook.Unity after adding the folder:

  1. Right click on Facebook.Unity folder -> Create -> Assembly Definition
  2. 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

samavan avatar May 10 '21 08:05 samavan

However after compiling on device :

  1. press FB.Init
  2. press Classic Login
  3. press Graph Request
  4. press Basic request - Me >> give error log from Xcode as below Screen Shot 2564-05-10 at 16 01 40

Any idea? O_o...

samavan avatar May 10 '21 08:05 samavan

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

binouze avatar May 10 '21 09:05 binouze

However after compiling on device :

  1. press FB.Init
  2. press Classic Login
  3. press Graph Request
  4. press Basic request - Me >> give error log from Xcode as below Screen Shot 2564-05-10 at 16 01 40

Any idea? O_o...

Just open the file above and apply the changes. Then recompile, get the dll and replace over your project..

farahjr avatar May 10 '21 14:05 farahjr

@binouze @farahjr now working a charm, thanks for the fast support! ;)

samavan avatar May 12 '21 11:05 samavan

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

indra452 avatar May 17 '21 15:05 indra452

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.

visualbruno avatar May 17 '21 15:05 visualbruno

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!

indra452 avatar May 18 '21 02:05 indra452

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 :)

psonichicmic avatar Jun 04 '21 06:06 psonichicmic

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?

wingsmight avatar Jun 09 '21 17:06 wingsmight

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.

pacolaf avatar Jun 11 '21 11:06 pacolaf

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 ?

visualbruno avatar Jun 11 '21 11:06 visualbruno

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

wingsmight avatar Jun 11 '21 17:06 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 ?

Thank you! It solves the login problem. I don't use the "share" function either, so I cannot test it.

pacolaf avatar Jun 14 '21 17:06 pacolaf

Hi @wingsmight FB.ShareLink works for me. Did you install first the SDK from Facebook and then overwrite just the DLLs I shared ?

visualbruno avatar Jun 15 '21 06:06 visualbruno

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 avatar Jun 15 '21 06:06 wingsmight

@wingsmight Someone created an issue about this bug: https://github.com/facebook/facebook-sdk-for-unity/issues/553

visualbruno avatar Jun 20 '21 19:06 visualbruno

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

joaquingrech avatar Jul 14 '21 01:07 joaquingrech

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.

pacolaf avatar Jul 27 '21 15:07 pacolaf

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+

snorrsi avatar Jul 28 '21 18:07 snorrsi