Example #1
0
 private void TestValidation()
 {
     VKSDK.API("account.testValidation", new Dictionary <string, string>(), (result) =>
     {
         Status = "API.account.testValidation call completed: " + result.ToString();
     });
 }
Example #2
0
        public void initSocialVk(string par)
        {
            string[] options = JsonHelper.Deserialize <string[]>(par);
            VKSDK.AccessTokenReceived += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine("Access token recieved " + args);
                JObject res = new JObject();
                res.Add("token", args.NewToken.AccessToken);
                DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res.ToString()));
                // TODO load user's profile
            };

            VKSDK.CaptchaRequest = (VKCaptchaUserRequest captchaUserRequest, Action <VKCaptchaUserResponse> action) =>
            {
                System.Diagnostics.Debug.WriteLine("Captcha request " + captchaUserRequest);
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Captcha request"));
            };

            VKSDK.AccessDenied += (sender, args) =>
            {
                System.Diagnostics.Debug.WriteLine("Access denied " + args);
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Access denied"));
            };

            VKSDK.Initialize(options[0]);
            VKSDK.WakeUpSession();

            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "VK Plugin inited"));
        }
Example #3
0
 private void CallApi()
 {
     VKSDK.API("users.get", new Dictionary <string, string>(), (result) =>
     {
         Status = "API.users.get call completed: " + result.ToString();
     });
 }
 protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
 {
     base.OnNavigatingFrom(e);
     if (e.NavigationMode == NavigationMode.Back && !_processedResult)
     {
         VKSDK.ProcessLoginResult(null, _isValidating, _validationCallback);
     }
 }
 protected override void OnClosing()
 {
     base.OnClosing();
     if (!_processedResult)
     {
         VKSDK.ProcessLoginResult(null, _isValidating, _validationCallback);
     }
 }
Example #6
0
        private void OnInitComplete()
        {
            Status = "Init completed: SDK version =  " + VKSDK.SDKVersion + ", appId = " + VKSDK.AppId + ", isLoggedIn = " + VKSDK.IsLoggedIn;

#if UNITY_ANDROID
            Status += ", cert. fingerprint= " + VKSDK.GetExtraData(VKSDK.EXTRA_ANDROID_CERTIFICATE_FINGERPRINT_KEY);
#endif
        }
Example #7
0
 public void logout(string par)
 {
     DispatchInvoke(() =>
     {
         VKSDK.Logout();
         DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
     });
 }
Example #8
0
 public MainPage()
 {
     this.InitializeComponent();
     this.NavigationCacheMode = NavigationCacheMode.Required;
     VKSDK.Initialize("5528332");
     //VKSDK.WakeUpSession();
     VKSDK.Authorize(_scope, false, false);
 }
Example #9
0
        protected override void GetGui()
        {
            bool enabled = GUI.enabled;

            if (this.Button("VK.Init"))
            {
                try
                {
                    VKSDK.Init(OnInitComplete);
                    this.Status = "VK.Init() called with " + VKSDK.AppId;
                }
                catch (Exception exc)
                {
                    Status = "VK.Init faled: " + exc.Message;
                }

                VKSDK.OnAccessTokenChanged = (at) =>
                {
                    this.Status += Environment.NewLine + " AccessToken changed!";
                };
            }

            GUI.enabled = enabled && VKSDK.IsInitialized;
            if (this.Button("Login"))
            {
                this.CallLogin();
                this.Status = "Login called";
            }

            GUI.enabled = enabled && VKSDK.IsLoggedIn;
            if (this.Button("Logout"))
            {
                CallLogout();
                Status = "Logout called";
            }

            GUI.enabled = enabled && VKSDK.IsLoggedIn;
            if (this.Button("API call (user.get)"))
            {
                CallApi();
                Status = "API.user.get is called";
            }

            if (Button("API call (friends.get)"))
            {
                CallGetFriends();
                Status = "API.friends.get is called";
            }

            if (Button("Test validation"))
            {
                TestValidation();
                Status = "API.account.testValidation is called";
            }

            GUI.enabled = enabled;
        }
Example #10
0
 private void CallGetFriends()
 {
     VKSDK.API("friends.get", new Dictionary <string, string>()
     {
         { "order", "hints" }
     }, (result) =>
     {
         Status = "API.friends.get call completed: " + result.ToString();
     });
 }
Example #11
0
        public void login(string par)
        {
            string[]      _scope = JsonHelper.Deserialize <string[]>(JsonHelper.Deserialize <string[]>(par)[0]);
            List <String> scope  = new List <string>(_scope);

            DispatchInvoke(() =>
            {
                VKSDK.Authorize(scope, false, false);
            });
        }
Example #12
0
        public MainPage()
        {
            this.InitializeComponent();
            this.NavigationCacheMode = NavigationCacheMode.Required;

            VKSDK.Initialize("5650916");
            VKSDK.Authorize(_scope, false, false);
            Player.CurrentStateChanged      += Player_CurrentStateChanged;
            Player.BufferingProgressChanged += Player_BufferingProgressChanged;
            // Player.DownloadProgressChanged += Player_DownloadProgressChanged;
        }
Example #13
0
        public static void HandleProtocolLaunch(ProtocolActivatedEventArgs protocolArgs)
        {
            if (protocolArgs.Uri.OriginalString.StartsWith("vk") && protocolArgs.Uri.OriginalString.Contains("://authorize"))
            {
                var launchUriDecoded = protocolArgs.Uri.ToString();
                launchUriDecoded = launchUriDecoded.Replace("authorize/#", "authorize/?");

                var innerQueryParamsString = VKUtil.GetParamsOfQueryString(launchUriDecoded);

                VKSDK.ProcessLoginResult(innerQueryParamsString, false, null);
            }
        }
        private void BrowserOnNavigating(object sender, NavigatingEventArgs args)
        {
            var url = args.Uri.AbsoluteUri;

            if (url.StartsWith(REDIRECT_URL))
            {
                var result = url.Substring(url.IndexOf('#') + 1);

                _processedResult = true;
                VKSDK.ProcessLoginResult(result, _isValidating, _validationCallback);
                RootFrame.GoBack();
            }
        }
        private void BrowserOnNavigating(WebView sender, WebViewNavigationStartingEventArgs args)
        {
            var url = args.Uri.AbsoluteUri;

            if (url.StartsWith(REDIRECT_URL) && !_processedResult)
            {
                var result = url.Substring(url.IndexOf('#') + 1);

                _processedResult = true;
                VKSDK.ProcessLoginResult(result, _isValidating, _validationCallback);
                this.IsShown = false;
            }
        }
Example #16
0
 // Before Scene Started
 void Awake()
 {
     // Check SDK Instance
     try{
         if (SDK != null)                     // Has SDK Instance
         {
             VK = SDK.GetComponent <VKSDK>(); // Get Component
         }
         else
         {
             SDK = GameObject.Find("VKSDK").transform.gameObject;
             VK  = SDK.GetComponent <VKSDK>(); // Get Component
         }
     } catch (Exception ex) {
         throw new Exception("На сцене отсутствует объект VK SDK");
     }
 }
Example #17
0
    public void OnLoginClick()
    {
        Debug.Log("Login clicked!");
        VK.Unity.VKSDK.Init(new VKInitParams {
            ApiVersion = "5.62", AppId = 5798402
        }, () =>
        {
            Debug.Log("Initialization completed");

            VKSDK.LogIn(new List <Scope> {
                Scope.Audio, Scope.Messages
            }, (authResp) =>
            {
                Debug.Log("Logged in " + authResp.accessToken);
            });
        });
    }
Example #18
0
        public void wall_post(string par)
        {
            string[]           options = JsonHelper.Deserialize <string[]>(par);
            VKPublishInputData data    = new VKPublishInputData();

            try {
                JObject p    = JObject.Parse(options[0]);
                var     dict = p.ToObject <Dictionary <string, string> >();
                data.Text = dict["message"];
                // TODO links and images
            } catch (Exception e) {
                data.Text = options[0];
            }
            DispatchInvoke(() => {
                VKSDK.Publish(data);
            });
        }
Example #19
0
        public MainPage()
        {
            InitializeComponent();
            AuthorizeButton.Click += AuthorizeButtonOnClick;

            VKSDK.Initialize("4460217");

            VKSDK.AccessTokenReceived += (sender, args) =>
            {
                UpdateUIState();
            };

            VKSDK.WakeUpSession();

            VKSDK.CaptchaRequest = CaptchaRequest;

            UpdateUIState();
        }
Example #20
0
        private void Publish_Click(object sender, RoutedEventArgs e)
        {
            var    rs          = Application.GetResourceStream(new Uri("TestImage.jpg", UriKind.Relative));
            Stream imageStream = rs.Stream;

            var inputData = new VKPublishInputData
            {
                Text         = "В Доме Зингера",
                Image        = imageStream,
                ExternalLink = new VKPublishInputData.VKLink
                {
                    Title    = "VK",
                    Subtitle = "VKontakte",
                    Uri      = "http://VK.com"
                }
            };

            VKSDK.Publish(inputData);
        }
        public MainPage()
        {
            this.InitializeComponent();
            AuthorizeButton.Click  += AuthorizeButtonOnClick;
            AuthorizeButton2.Click += AuthorizeButton2_Click;
            VKSDK.Initialize("4460217");

            VKSDK.AccessTokenReceived += (sender, args) =>
            {
                UpdateUIState();
            };

            VKSDK.WakeUpSession();

            VKSDK.CaptchaRequest = CaptchaRequest;

            this.NavigationCacheMode = NavigationCacheMode.Required;

            UpdateUIState();
        }
Example #22
0
        private void DoDispatch <T>(
            Dictionary <string, string> parametersDict,
            Action <VKBackendResult <T> > callback,
            Func <string, T> customDeserializationFunc = null)
        {
            parametersDict["v"] = VKSDK.API_VERSION;

            var accessToken = VKSDK.GetAccessToken();

            if (accessToken != null)
            {
                parametersDict["access_token"] = accessToken.AccessToken;
            }

            var dispatchUri = string.Format(REQUEST_BASE_URI_FRM, _parameters.MethodName);

            VKHttpRequestHelper.DispatchHTTPRequest(
                dispatchUri,
                parametersDict,
                (httpResult) =>
            {
                if (httpResult.IsSucceeded)
                {
                    var backendResult = GetBackendResultFromString <T>(httpResult.Data, customDeserializationFunc);


                    if (backendResult.ResultCode == VKResultCode.CaptchaRequired)
                    {
                        var captchaRequest = new VKCaptchaUserRequest
                        {
                            CaptchaSid = backendResult.Error.captcha_sid,
                            Url        = backendResult.Error.captcha_img
                        };

                        VKSDK.InvokeCaptchaRequest(captchaRequest,
                                                   (captchaResponse) =>
                        {
                            if (!captchaResponse.IsCancelled)
                            {
                                var parametersWithCaptcha = new Dictionary <string, string>(parametersDict);

                                parametersWithCaptcha["captcha_sid"] = captchaResponse.Request.CaptchaSid;
                                parametersWithCaptcha["captcha_key"] = captchaResponse.EnteredString;

                                DoDispatch(parametersWithCaptcha,
                                           callback,
                                           customDeserializationFunc);
                            }
                            else
                            {
                                InvokeSafely(() => callback(new VKBackendResult <T>()
                                {
                                    ResultCode = VKResultCode.CaptchaControlCancelled
                                }));
                            }
                        });
                    }
                    else if (backendResult.ResultCode == VKResultCode.ValidationRequired)
                    {
                        var validationRequest = new VKValidationRequest
                        {
                            ValidationUri = backendResult.Error.redirect_uri
                        };

                        VKSDK.InvokeValidationRequest(validationRequest,
                                                      (vr) =>
                        {
                            if (vr.IsSucceeded)
                            {
                                DoDispatch(parametersDict, callback, customDeserializationFunc);
                            }
                            else
                            {
                                InvokeSafely(() => callback(new VKBackendResult <T> {
                                    ResultCode = VKResultCode.ValidationCanceslledOrFailed
                                }));
                            }
                        });
                    }
                    else
                    {
                        InvokeSafely(() => callback(backendResult));
                    }
                }
                else
                {
                    var backendResult = new VKBackendResult <T> {
                        ResultCode = VKResultCode.CommunicationFailed
                    };
                    InvokeSafely(() => callback(backendResult));
                }
            });
        }
 private void AuthorizeButtonOnClick(object sender, RoutedEventArgs routedEventArgs)
 {
     VKSDK.Authorize(_scope, false, false);
 }
 private void LogoutButton_Click(object sender, RoutedEventArgs e)
 {
     VKSDK.Logout();
     UpdateUIState();
 }
 void AuthorizeButton2_Click(object sender, RoutedEventArgs e)
 {
     VKSDK.Authorize(_scope, false, false, LoginType.VKApp);
 }
Example #26
0
 private void InitializeSDK()
 {
     VKSDK.Initialize("4460217");
     VKSDK.WakeUpSession();
 }
Example #27
0
 private void CallLogout()
 {
     VKSDK.Logout();
 }
Example #28
0
 private void CallLogin()
 {
     VKSDK.Login(new List <Scope> {
         Scope.Friends, Scope.Offline
     }, OnLoginCompleted);
 }