예제 #1
0
        public void Login(Context context)
        {
            this.context = context.ApplicationContext;
            if (string.IsNullOrEmpty(CurrentPlatform))
            {
                return;
            }

            // 初始化SDK
            ShareSDK.InitSDK(this.context);
            Platform plat = ShareSDK.GetPlatform(CurrentPlatform);

            if (plat == null)
            {
                return;
            }

            if (plat.IsAuthValid)
            {
                plat.RemoveAccount(true);
                return;
            }

            //使用SSO授权,通过客户单授权
            plat.SSOSetting(false);

            plat.Complete += (sender, e) => {
                var platName = e.P0.Name;
            };

            plat.Error += (sender, e) => {
            };

            plat.Cancel += (sender, e) => {
            };

            plat.ShowUser(null);
        }
        /*
         * 演示执行第三方登录/注册的方法
         * <p>
         * 这不是一个完整的示例代码,需要根据您项目的业务需求,改写登录/注册回调函数
         *
         * @param platformName 执行登录/注册的平台名称,如:SinaWeibo.NAME
         */
        private void login(string platformName)
        {
            LoginApi api = new LoginApi();

            // 初始化SDK
            ShareSDK.InitSDK(ApplicationContext);
            Platform plat = ShareSDK.GetPlatform(platformName);

            if (plat == null)
            {
                return;
            }

            if (plat.IsAuthValid)
            {
                plat.RemoveAccount(true);
                return;
            }

            //使用SSO授权,通过客户单授权
            plat.SSOSetting(false);

            plat.Complete += (sender, e) => {
                // 填写处理注册信息的代码,返回true表示数据合法,注册页面可以关闭
                RunOnUiThread(() => {
                    Toast.MakeText(this, "登录成功。", ToastLength.Short).Show();
                });
            };

            plat.Error += (sender, e) => {
            };

            plat.Cancel += (sender, e) => {
            };

            plat.ShowUser(null);
        }