Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ArgumentException in when send GET requests in Unity 2021.1 #539

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions Facebook.Unity/Results/GraphResult.cs
Expand Up @@ -22,20 +22,25 @@ namespace Facebook.Unity
{
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

internal class GraphResult : ResultBase, IGraphResult
{
internal GraphResult(WWW result) : base(new ResultContainer(result.text), result.error, false)
{
internal GraphResult(UnityWebRequestAsyncOperation result) :
base(new ResultContainer(result.webRequest.downloadHandler.text), result.webRequest.error, false)
{

this.Init(this.RawResult);

// The WWW object will throw an exception if accessing the texture field and
// an error has occured.
if (result.error == null)
if (string.IsNullOrEmpty(result.webRequest.error))
{
// The Graph API does not return textures directly, but a few endpoints can
// redirect to images when no 'redirect=false' parameter is specified. Ex: '/me/picture'
this.Texture = result.texture;

this.Texture = new Texture2D(2, 2);
this.Texture.LoadImage(result.webRequest.downloadHandler.data);
}
}

Expand Down
21 changes: 11 additions & 10 deletions Facebook.Unity/Utils/AsyncRequestString.cs
Expand Up @@ -24,6 +24,7 @@ namespace Facebook.Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

/*
* A short lived async request that loads a FBResult from a url endpoint
Expand Down Expand Up @@ -80,7 +81,7 @@ internal class AsyncRequestString : MonoBehaviour

internal IEnumerator Start()
{
WWW www;
UnityWebRequestAsyncOperation webRequestOperation;
if (this.method == HttpMethod.GET)
{
string urlParams = this.url.AbsoluteUri.Contains("?") ? "&" : "?";
Expand All @@ -92,14 +93,13 @@ internal IEnumerator Start()
}
}

Dictionary<string, string> headers = new Dictionary<string, string>();

UnityWebRequest webRequest = UnityWebRequest.Get(url + urlParams);
if (Constants.CurrentPlatform != FacebookUnityPlatform.WebGL)
{
headers["User-Agent"] = Constants.GraphApiUserAgent;
webRequest.SetRequestHeader("User-Agent", Constants.GraphApiUserAgent);
}

www = new WWW(this.url + urlParams, null, headers);
webRequestOperation = webRequest.SendWebRequest();
}
else
{
Expand Down Expand Up @@ -127,18 +127,19 @@ internal IEnumerator Start()
this.query.headers["User-Agent"] = Constants.GraphApiUserAgent;
}

www = new WWW(this.url.AbsoluteUri, this.query);
UnityWebRequest webRequest = UnityWebRequest.Post(url.AbsoluteUri, query);
webRequestOperation = webRequest.SendWebRequest();
}

yield return www;
yield return webRequestOperation;

if (this.callback != null)
{
this.callback(new GraphResult(www));
this.callback(new GraphResult(webRequestOperation));
}

// after the callback is called, www should be able to be disposed
www.Dispose();
// after the callback is called, web request should be able to be disposed
webRequestOperation.webRequest.Dispose();
MonoBehaviour.Destroy(this);
}

Expand Down