Пример #1
0
    void GetShareData(string error, IJSonObject data)
    {
        tries++;
        Debug.Log(tries);
        if (error != null)
        {
            Debug.Log(error);
            tries = 0;
            if (tempCallback != null)
            {
                tempCallback("Connection Error. Please try again later.", tempFace, tempParams, null);
            }
            tempFace     = "";
            tempCallback = null;
            tempParams   = new Dictionary <string, string>();
        }
        else
        {
            if (data["result"].ToString() == "shared")
            {
                Debug.Log("deu shared..." + data);
                tries = 0;
                if (tempCallback != null)
                {
                    tempCallback(null, tempFace, tempParams, data["post_id"].StringValue);
                }

                tempFace     = "";
                tempCallback = null;
                tempParams   = new Dictionary <string, string>();
            }
            else
            {
                Debug.Log("deu not shared...");
                if (tries > 5)
                {
                    Debug.Log("ja tentou mais de 5 vezes");
                    tries = 0;
                    if (tempCallback != null)
                    {
                        tempCallback("Connection Error. Please try again later.", tempFace, tempParams, null);
                    }

                    tempFace     = "";
                    tempCallback = null;
                    tempParams   = new Dictionary <string, string>();
                }
                else
                {
                    Debug.Log("tentou menos, tentar de novo!");
                    Invoke("promptAgain", 1f);
                }
            }
        }
    }
Пример #2
0
 public GenerateState(string facebookId, Dictionary <string, string> parameters, FacebookAPI.WallPostCallback callback, int tries = 0)
 {
     stateType = StateType.WallPost; globalFacebookId = facebookId; wallParameters = parameters; wallPostCallback = callback;  this.tries = tries;
 }
Пример #3
0
    // Funcao para fazer uma postagem no mural do usuario/amigo
    // Retorna ID do post se nao for feito por dialogo
    public IEnumerator WallPost(string _facebookId, Dictionary <string, string> parameters, FacebookAPI.WallPostCallback callback, int tries = 0)
    {
        // Cria URL do request
        bool   isDialog = (parameters != null && parameters.ContainsKey("dialog")) ? true : false;
        string url      = (isDialog) ? DIALOG_URL : GRAPH_URL;

        if (!isDialog)
        {
            url += _facebookId + "/";
        }
        url += "feed/?";

        // Se for dialogo, adiciona redirecionamento para php aonde fecha o browser nativo do Prime31
        // e informacoes extras para fazer o post
        if (isDialog)
        {
            url += "app_id=" + facebookId + "&";
            url += "redirect_uri=" + WWW.EscapeURL(Flow.URL_BASE + "login/tables/input_share.php?" +
                                                   //"app_id=" + Info.appId + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())) +"&device=" + GameInfo.device()) + "&";
                                                   "app_id=" + Info.appId + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())) + "&device=" + SystemInfo.deviceUniqueIdentifier.Replace("-", "")) + "&";
            if (_facebookId != "me")
            {
                url += "to=" + WWW.EscapeURL(_facebookId) + "&";
            }
        }
        else
        {
            url += "method=post&";
        }

        // Checa se os parametros enviados nao sao nulos e adiciona no form
        if (parameters != null)
        {
            if (parameters.ContainsKey("message"))
            {
                url += "message=" + WWW.EscapeURL(parameters["message"]) + "&";
            }
            if (parameters.ContainsKey("name"))
            {
                url += "name=" + WWW.EscapeURL(parameters["name"]) + "&";
            }
            if (parameters.ContainsKey("link"))
            {
                url += "link=" + WWW.EscapeURL(parameters["link"]) + "&";
            }
            if (parameters.ContainsKey("description"))
            {
                url += "description=" + WWW.EscapeURL(parameters["description"]) + "&";
            }
            if (parameters.ContainsKey("picture"))
            {
                url += "picture=" + WWW.EscapeURL(parameters["picture"]) + "&";
            }
        }

        // Se for nulo, enviar erro para o callback
        else
        {
            if (callback != null)
            {
                callback(NULL_PARAMETERS, facebookId, parameters, null);
            }
            Debug.LogWarning(NULL_PARAMETERS);
            yield break;
        }

        // Access token do usuario
        url += "access_token=" + WWW.EscapeURL(facebookToken);

        // Se nao for dialogo, fazer o post
        if (!isDialog)
        {
            WWW wallPost = new WWW(url);
            yield return(wallPost);

            // Se houver algum erro, enviar erro para o callback
            if (wallPost.error != null)
            {
                // Envia para o callback
                if (callback != null)
                {
                    callback(wallPost.error, _facebookId, parameters, null);
                }

                // Cacheia a conexão atual para tentar novamente apos o "giro"
                Login(
                    new GenerateState(_facebookId, parameters, callback)
                    , HandleState
                    );
                yield break;
            }

            // Caso contrario, decodar JSON recebido
            else
            {
                IJSonObject data = wallPost.text.ToJSon();

                // Se o JSON recebido for invalido, retornar e enviar para o callback
                if (data.IsEmpty() || data.IsError())
                {
                    if (callback != null)
                    {
                        callback("Invalid JSon: " + wallPost.text, _facebookId, parameters, null);
                    }

                    yield break;
                }

                // Envia ID do post para o callback
                if (callback != null)
                {
                    callback(null, _facebookId, parameters, data.GetString("id"));
                }
            }
        }

        // Se for dialogo, abrir a url no navegador do Prime31
        else
        {
            Flow.game_native.openUrlInline(url);

            tempFace     = _facebookId;
            tempParams   = parameters;
            tempCallback = callback;

            if (_facebookId == "me")
            {
                new GameJsonAuthConnection(Flow.URL_BASE + "login/tables/check_share.php", GetShareData).connect();
            }
            else
            {
                if (callback != null)
                {
                    callback(null, _facebookId, parameters, null);
                }
            }
            // Como nao tem como receber o callback do navegador do Prime31
            // enviar callback de sucesso (mesmo se o usuario nao estiver postado)
        }
        yield break;
    }
Пример #4
0
		public GenerateState(string facebookId, Dictionary<string, string> parameters, FacebookAPI.WallPostCallback callback, int tries = 0)
		{ stateType = StateType.WallPost; globalFacebookId = facebookId; wallParameters = parameters; wallPostCallback = callback;  this.tries = tries; }
Пример #5
0
	void GetShareData(string error, IJSonObject data)
	{
		tries++;
		if(error != null) 
		{
			Debug.Log(error);
			tries = 0;
			if (tempCallback != null) tempCallback("Connection Error. Please try again later.", tempFace, tempParams, null);
			tempFace = "";
			tempCallback = null;
			tempParams = new Dictionary<string, string>();
		}
		else
		{
			if(data["result"].ToString() == "shared")
			{
				tries = 0;
				if (tempCallback != null)
					tempCallback(null, tempFace, tempParams, data["post_id"].StringValue);
				
				tempFace = "";
				tempCallback = null;
				tempParams = new Dictionary<string, string>();
			}
			else
			{
				if(tries > 5)
				{
					tries = 0;
					if (tempCallback != null)
					tempCallback("Connection Error. Please try again later.", tempFace, tempParams, null);
					
					tempFace = "";
					tempCallback = null;
					tempParams = new Dictionary<string, string>();
				}
				else 
				{
					Invoke("promptAgain",1f);
				}
			}
				
		}
		
	}
Пример #6
0
    // Funcao para fazer uma postagem no mural do usuario/amigo
    // Retorna ID do post se nao for feito por dialogo
	public IEnumerator WallPost(string _facebookId, Dictionary<string, string> parameters, FacebookAPI.WallPostCallback callback, int tries = 0)
	{
        // Cria URL do request
		bool isDialog = (parameters != null && parameters.ContainsKey("dialog")) ? true : false;
		string url = (isDialog) ? DIALOG_URL : GRAPH_URL;
		if (!isDialog) url += _facebookId + "/";
		url += "feed/?";
		
        // Se for dialogo, adiciona redirecionamento para php aonde fecha o browser nativo do Prime31
        // e informacoes extras para fazer o post
		if (isDialog)
        {
			url += "app_id=" + facebookId + "&";
			url += "redirect_uri=" + WWW.EscapeURL(Flow.URL_BASE + "login/tables/input_share.php?" +
				//"app_id=" + Info.appId + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())) +"&device=" + GameInfo.device()) + "&";
				"app_id=" + Info.appId + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())) +"&device=" + SystemInfo.deviceUniqueIdentifier.Replace("-", "")) + "&";
			if (_facebookId != "me")
                url += "to=" + WWW.EscapeURL(_facebookId) + "&";
		}
        else url += "method=post&";
		
        // Checa se os parametros enviados nao sao nulos e adiciona no form
		if (parameters != null)
        {
			if (parameters.ContainsKey("message"))
				url += "message=" + WWW.EscapeURL(parameters["message"]) + "&";
			if (parameters.ContainsKey("name"))
				url += "name=" + WWW.EscapeURL(parameters["name"]) + "&";
			if (parameters.ContainsKey("link"))
				url += "link=" + WWW.EscapeURL(parameters["link"]) + "&";
			if (parameters.ContainsKey("description"))
				url += "description=" + WWW.EscapeURL(parameters["description"]) + "&";
			if (parameters.ContainsKey("picture"))
				url += "picture=" + WWW.EscapeURL(parameters["picture"]) + "&";
		}

        // Se for nulo, enviar erro para o callback
        else
        {
			if (callback != null)
				callback(NULL_PARAMETERS, facebookId, parameters, null);
			Debug.LogWarning(NULL_PARAMETERS);
			yield break;
		}

        // Access token do usuario
		url += "access_token=" + WWW.EscapeURL(facebookToken);
		
        // Se nao for dialogo, fazer o post
		if (!isDialog)
        {
			WWW wallPost = new WWW(url);
			yield return wallPost;

            // Se houver algum erro, enviar erro para o callback
			if (wallPost.error != null)
            {
                // Envia para o callback
				if (callback != null)
					callback(wallPost.error, _facebookId, parameters, null);

                // Cacheia a conexão atual para tentar novamente apos o "giro"
				Login(
                    new GenerateState(_facebookId, parameters, callback)
                    , HandleState
                );
				yield break;
			}

            // Caso contrario, decodar JSON recebido
            else
            {
				IJSonObject data = wallPost.text.ToJSon();
				
				// Se o JSON recebido for invalido, retornar e enviar para o callback
				if (data.IsEmpty() || data.IsError())
				{
					if (callback != null) 
						callback("Invalid JSon: " + wallPost.text, _facebookId, parameters, null);
					
					yield break;
				}
				
                // Envia ID do post para o callback
				if (callback != null)
					callback(null, _facebookId, parameters, data.GetString("id"));
			}
		}

        // Se for dialogo, abrir a url no navegador do Prime31
        else
        {
			// Up Top Fix me (dialog)
			//GameGUI.game_native.openUrlInline(url);
			Flow.game_native.openUrlInline(url);
			
			
			tempFace = _facebookId;
			tempParams = parameters;
			tempCallback = callback;
			
			if(_facebookId == "me") 
			{
				new GameJsonAuthConnection(Flow.URL_BASE+"login/tables/check_share.php",GetShareData).connect();
			}
			else
			{
				if (callback != null) callback(null, _facebookId, parameters, null);
			}
            // Como nao tem como receber o callback do navegador do Prime31
            // enviar callback de sucesso (mesmo se o usuario nao estiver postado)
			
		}
		yield break;
	}
Пример #7
0
	void GetShareData(string error, IJSonObject data)
	{
		tries++;
		Debug.Log(tries);
		if(error != null) 
		{
			Debug.Log(error);
			tries = 0;
			if (tempCallback != null) tempCallback("Connection Error. Please try again later.", tempFace, tempParams, null);
			tempFace = "";
			tempCallback = null;
			tempParams = new Dictionary<string, string>();
		}
		else
		{
			if(data["result"].ToString() == "shared")
			{
				Debug.Log("deu shared..."+data);
				tries = 0;
				if (tempCallback != null) tempCallback(null, tempFace, tempParams, data["post_id"].StringValue);
				
				tempFace = "";
				tempCallback = null;
				tempParams = new Dictionary<string, string>();
			}
			else
			{
				Debug.Log("deu not shared...");
				if(tries > 5)
				{
					Debug.Log("ja tentou mais de 5 vezes");
					tries = 0;
					if (tempCallback != null)
					tempCallback("Connection Error. Please try again later.", tempFace, tempParams, null);
					
					tempFace = "";
					tempCallback = null;
					tempParams = new Dictionary<string, string>();
				}
				else 
				{
					Debug.Log("tentou menos, tentar de novo!");
					Invoke("promptAgain",1f);
				}
			}
				
		}
		
	}