Facebook-sdk-for-unity: ArgumentException when use FB.API in Unity 2021.1

Created on 25 Mar 2021  ·  38Comments  ·  Source: facebook/facebook-sdk-for-unity

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);
bug

Most helpful comment

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

All 38 comments

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

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

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

image

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

image

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

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

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.

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

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

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

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 :

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yasuohasegawa picture yasuohasegawa  ·  4Comments

manofspirit picture manofspirit  ·  6Comments

michelleran picture michelleran  ·  6Comments

naklow12 picture naklow12  ·  6Comments

Duke74 picture Duke74  ·  4Comments