Hi All,
i am working on instagram authorisation from inside unity
now to achieve this i have to arrange a SendMessage to unity from an HTML which is placed at the same path where the unity3d file and the unity weblayer.html file is placed.
Now here is the code for the new HTML file created after authorization
<script type="text/javascript" src="unityobject2.js">
<!--
//initializing the WebPlayer
var u = new UnityObject2();
u.initPlugin(jQuery("#unityPlayer")[0], "example.unity3d");
u.getUnity().SendMessage("InstagramManager", "AccestokenFromWeb", "Hello from a web page!");
-->
</script>
i a somehow not able to figure out why this not calling the message inside unity. the object name and message name are correct, i even checked the chrome console to see if there was any error in the HTML file but it wasn’t.
The typical problem here is that you’ve called initPlugin
, and then instantly called SendMessage
. The docs at:
http://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html
recommend that you wait for the game to load before trying SendMessage
. One way to handle this is to have your InstagramManager
object call out to the HTML JS when it starts up, using Application.ExternalCall()
. The function in the HTML JS that you call can then use SendMessage
to talk back to the Unity script, and pass in the access token.
i guess i have to answer this myself,
Below is the code for both the HTML file and the TXT file placed inside unity
HTML File
<title>Authorization Window</title>
<script language="JavaScript">
if(window.location.hash)
{
var access_token = window.location.hash.split('&')[0].replace('#access_token=', '');
TokenRecieved(access_token);
}
function TokenRecieved(token)
{
if (window.opener && !window.opener.closed)
window.opener.TokenRecieved(token);
window.close();
}
</script>
TXT File(Inside Unity)
var myWindow;
function Authenticate()
{
var F = 0;
if (screen.height > 500)
{
F = Math.round((screen.height / 2) - (250))
}
myWindow = window.open ("https://instagram.com/oauth/authorize/?client_id=%clientID%&redirect_uri=%callback_uri%&response_type=token","Instagram","menubar=1,resizable=1,width=500,height=500,scrollbars=1,left="+Math.round((screen.width/2)-250)+",top="+F);
}
function TokenRecieved(token)
{
u.getUnity().SendMessage("InstagramAPI","TokenRecieved",token);
}
i hope other might get help from this and doesn’t waste there time as i did