Пример #1
0
 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);
 }
Пример #2
0
        private void Api(string query, HTTP.Method method, HTTP.Format format, Dictionary <string, string> args, OKRequestCallback callback, bool useSession = true)
        {
            args.Add(ParamApplicationKey, appKey);
            args.Add(ParamMethod, query);
            args.Add(ParamFormat, format.ToString());
            args.Add(ParamPlatform, GetPlatform().ToUpper());

            // Check if target API requires SdkToken.
            if (OKMethod.RequiresSdkToken(query))
            {
                args.Add(ParamSdkToken, unitySessionKey);
            }

            // Override useSession for some API requests that fail if called within session.
            if (!OKMethod.RequiresSession(query))
            {
                useSession = false;
            }

            string url = useSession ? GetApiUrl(args) : GetApiNoSessionUrl(args);

            new HTTP.Request(url, method, format).Send(request =>
            {
                //check for error
                Hashtable obj = request.response.Object;
                if (obj != null)
                {
                    if (obj.ContainsKey("error_code"))
                    {
                        string errorCode = obj["error_code"].ToString();
                        string errorMsg  = obj["error_msg"].ToString();
                        switch (errorCode)
                        {
                        case "100":
                            if (errorMsg == "PARAM : Missed required parameter: access_token")
                            {
                                Debug.Log("Missing access token - trying to auto refresh session");
                                RefreshAuth(refreshed => {
                                    Debug.Log("REFRESHED: " + refreshed);
                                });
                            }
                            break;

                        case "102":
                            Debug.Log("Session expired - trying to auto refresh session");
                            RefreshAuth(refreshed => {
                                Debug.Log("REFRESHED: " + refreshed);
                            });
                            break;

                        case "103":
                            Debug.Log("Invalid session key - trying to auto refresh session");
                            RefreshAuth(refreshed => {
                                Debug.Log("REFRESHED: " + refreshed);
                            });
                            break;

                        default:
                            Debug.LogWarning(query + " failed -> " + request.response.Error);
                            callback(request.response);
                            break;
                        }
                        return;
                    }
                }

                if (callback != null)
                {
                    callback(request.response);
                }
            });
        }
 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);
 }