- Home /
Using WWW / Unity3 and Making Calls to Facebook OpenGraph API
Hello.
I was wondering if it was possibly to make calls to the Facebook OpenGraph API, so my code is what's wrong.
Basically, is this Unities security, or is it my code...
Everything I do, will not return the correct data
IEnumerator Load() { //Security.PrefetchSocketPolicy("www.facebook.com", );
while (!CookieCutter.IsLoaded())
{
yield return StartCoroutine(WebUtils.WaitFor(0.1f));
}
string cookieValue = CookieCutter.GetCookie(theLimitCookieName);
if(string.IsNullOrEmpty(cookieValue))
{
cookieValue = CookieCutter.GetCookie(debugCookieName);
}
// --- Hash the cookie values
if (!string.IsNullOrEmpty(cookieValue))
{
cookieValue = cookieValue.Trim('\"');
string[] nameValues = cookieValue.Split('&');
Hashtable hashTable = new Hashtable();
foreach (string element in nameValues)
{
string[] splitElement = element.Split('=');
if(splitElement.Length == 2)
hashTable[splitElement[0].Trim('"')] = splitElement[1].Trim('"');
}
long.TryParse((string)hashTable["uid"], out _uid);
_accessToken = (string)hashTable["access_token"];
}
t = "LoadFriends : " + UID;
// --- Now lets do a web call
WWW fbFriendsReq = new WWW("https://graph.facebook.com/me/friends?access_token=" + UID);
yield return WebUtils.WaitForRequest(fbFriendsReq);
// --- these calls never return the correct data...isDone = false, and error is undefined
t = "Returned from WebUTils : Done : " + fbFriendsReq.isDone + " Error : " + fbFriendsReq.error;
t = "Recieved Friends : " + fbFriendsReq.text;
// --- Execution never makes it here
_friends = FacebookFriends.CreateFromJSON(fbFriendsReq.text);
t = "Friends Created From JSON";
yield return WebUtils.WaitFor(0.01f);
}
adding in Security.PrefetchSocketPolicy("graph.facebook.com", 80); still doesn't seem to solve my problems
Answer by JDonavan 1 · Nov 06, 2010 at 02:16 AM
The server you're connecting to would need to respond with a policy file that gives the Unity Web Player permission. So unless you can convince Facebook to put up a security file for all us Unity folks you're going to have to resort to the standard, call out to the enclosing web page trick.
Answer by stringa · Nov 06, 2010 at 01:12 AM
I see that... Security.PrefetchSocketPolicy("graph.facebook.com", 8080) is most likely the call I need to make. but what happens is that PrefetchPolicy returns false... ALWAYS...
This is the graph.facebook.com/crossdomain.xml
Is there something invalid about this domain policy?
Is my code bad above to do a web request?
This code used to work with Unity2.6, and I'm handling all your new security stuff...I just can't get it to work.
There is always the work around of reading it through my ASP page and sending it in through UnityObject.SendMsg...thus I can get around all of unity's "security"....
Also, This cross domain stuff, isn't really that secure....
Say I need to use Texture.SetPixel()... What I can do, is send it to myself, through a web-call, in my own IIS server.
For example : http://mydomain.com?convertImage="http://otherdomain.com/imagetoconvert.jpg"
and this Http request just returns the image...
Walla...now the image is coming from my own domain, and I can modify it with SetPixel.
I just circomvented any security you implemented...I know this works, because I've done it with flash.
Anyways, Why doesn't the WWW call work in the original post? Is there something fundamentally wrong with the WWW code? Can I expect that the line after yield return WWWcall, has a valid Object?
Thanks, stringa
Answer by stringa · Nov 06, 2010 at 06:35 AM
Is there something wrong with this crossdomain policy, that isn't supported by Unity?
<?xml version="1.0" ?>
<!DOCTYPE cross-domain-policy (View Source for full doctype...)>
<cross-domain-policy>
<allow-access-from domain="*" secure="false" />
<site-control permitted-cross-domain-policies="master-only" />
</cross-domain-policy>
Answer by Rageous · Sep 15, 2011 at 09:30 AM
PrefetchSocketPolicy needs an IP address, host name willn't work.