- Home /
Has anyone had success with Facebook's graph API in Unity's Flash export?
I am trying to pull information from Facebook (such as a user's feed, photos, friends, etc.) into an app that I am exporting to Flash, but I can't seem to receive any information except for very basic information from graph.facebook.com/me (and permissions). I am trying to use Unity's WWW class like so:
WWW www = new WWW("https://graph.facebook.com/me?access_token=" + myAccessToken);
yield return www;
Using this format--and a few other methods using actionscripts--I have so far been successful in redirecting users to the Facebook authentication page, accept additional necessary permissions (for reading a user's feed, viewing photos, etc.), return the user to my webpage with the flash app and an access code in the URL, read the code and use the WWW class to get the correct access token, store the token as a user preference, and finally query Facebook for information by using the access token.
As mentioned before, I can return some basic public information; however, I can't get private information--and even some public information such as friends. What troubles me most is that www.error is returning null while www.text simply returns an empty string ""; there should be an error if the access_token doesn't have correct permissions, and www.text should return something like "{ data:{} }" if an empty list is being returned. I've even tested the access_token in Facebook's "Graph API Explorer" page and I can access all the data to which I've granted permissions.
Has anyone else attempted accessing Facebook from a Unity3d Flash export? I could really use some ideas because I am running out. I've convinced myself it is some issue with the way that flash is using WWW because I have successfully returned a list of friends by running it from within Unity by pre-fetching my access_token and hardcoding it in.
Also, if anyone has successfully connected to Facebook through some method other than WWW, please let me know. I am open to other options.
Answer by cjrichards · Sep 17, 2012 at 07:59 PM
For anyone who is interested, I've found a solution from a different post--though the poster was having a slightly different issue:
http://answers.unity3d.com/questions/266934/getting-fatal-error-2030-using-www-in-flash.html
Basically, WWW still has a few bugs in the current Unity3d's flash export. The solution is to perform your http functions in an AS3 file while mirroring function and variable names in a .cs file (I assume javascript would work too?), using [NotRenamed] and [NotConverted]. Then you can call your AS3 functions from within your Unity3d app. More details are included in the link above. You can find more info on [NotRenamed] and [NotConverted] in Unity's script references.
One other thing to note: Even after converting my app to use AS3, I had an additional problem. By default, Facebook will return ALL of the info from your feed, list of friends, etc.; this was creating a "Fatal Error: null" because of buffer overflow (I think). Setting a limit on the amount of information returned (by adding ?limit=5 to the url, for example) fixed this issue. If this isn't an option for someone, maybe there is a way to modify the size of the buffer? If anyone knows how to do this, share your knowledge here for someone else's sake! (I haven't looked it up because I am fine with a size limit for now)
Your answer
![](https://koobas.hobune.stream/wayback/20220613081049im_/https://answers.unity.com/themes/thub/images/avi.jpg)