private void SdkInit(string sdkVersion, string deviceId, string clientType, string clientVersion, OKInitCallback callback)
        {
            Hashtable jsonData = new Hashtable {
                {"version", sdkVersion},
                {"device_id", deviceId},
                {"client_type", clientType},
                {"client_version", clientVersion}
            };
            Dictionary<string, string> args = new Dictionary<string, string> {
                {"method", OKMethod.SDK.init},
                {"application_key", appKey},
                {"session_data", JSON.Encode(jsonData)}
            };
            string url = string.Format("https://api.ok.ru/fb.do?{0}", URLParams(args));
            new HTTP.Request(url).Send(request =>
            {
                try
                {
                    if (request.response.Error != "")
                    {
                        IsInitialized = false;
                        if (callback != null)
                        {
                            callback(false);
                        }
                        Debug.Log("Odnoklassniki API initialization failed. Reason: " + request.response.Error);
                        return;
                    }

                    Hashtable response = request.response.Object;
                    unitySessionKey = (string) response["session_key"];
                    unitySecretSessionKey = (string) response["session_secret_key"];
                    apiServer = (string) response["api_server"];
                    activatedProfile = (bool) response["activated_profile"];

                    IsInitialized = true;
                    if (callback != null)
                    {
                        callback(true);
                    }

                    Debug.Log("Odnoklassniki API initialized successfully");
                }
                catch (Exception e)
                {
                    IsInitialized = false;
                    if (callback != null)
                    {
                        callback(false);
                    }
                    Debug.Log("Odnoklassniki API initialization failed. Exception: " + e.Message + ". Reason: " + request.response.Error);
                }
            });
        }
Example #2
0
 public static void Init(OKInitCallback callback = null)
 {
     if (IsInitialized)
     {
         Debug.Log("Odnoklassniki API already initialized");
         callback(true);
         return;
     }
     #if UNITY_ANDROID
     odnoklassniki = new GameObject("Odnoklassniki").AddComponent<AndroidOdnoklassniki>();
     odnoklassniki.Init(callback);
     #elif UNITY_IOS
     odnoklassniki = new GameObject("Odnoklassniki").AddComponent<IOSOdnoklassniki>();
     odnoklassniki.Init(callback);
     #else
     Debug.LogError("Odnoklassniki Unity SDK Unavailable: Set platform to either Android or iOS");
     odnoklassniki = null;
     callback(false);
     #endif
 }
 public void Init(OKInitCallback callback)
 {
     DontDestroyOnLoad(gameObject);
     AppId = OKSettings.AppId;
     appKey = OKSettings.AppKey;
     forceOAuth = OKSettings.ForceOAuth;
     fallbackToOAuth = OKSettings.FallbackToOAuth;
     HTTP.Request.LogAllRequests = OKSettings.LogAllRequests;
     httpFormat = OKSettings.UseXML ? HTTP.Format.XML : HTTP.Format.JSON;
     scope = OKSettings.Scope;
     debugAccessToken = OKSettings.DebugAccessToken;
     debugSessionKey = OKSettings.DebugSessionKey;
     ReportPaymentInit();
     SdkInit(OKSettings.SDK_VERSION, SystemInfo.deviceUniqueIdentifier, OKSettings.CLIENT_TYPE, OKSettings.CLIENT_VERSION, callback);
 }