コード例 #1
0
ファイル: Default.aspx.cs プロジェクト: Rick1206/innisfree
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            //Response.Write( GetBytesByImagePath("/img/bg1.jpg"));

             if (Session["Token"] == null)
             {

                 //string cusCallbackUrl = CallbackUrl + "?point=1";

                 OAuth myoauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, CallbackUrl);

                 String authUrl = myoauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);

                 Response.Redirect(authUrl);

             }
             else
             {

                 Sina = new Client(new OAuth(AppKey, AppSecret, Session["Token"].ToString(), null));
                 //用cookie里的accesstoken来实例化OAuth,这样OAuth就有操作权限了

                 UserID = Sina.API.Account.GetUID();
                 string weiboContent = "想让韩国国宝级彩妆大师朴泰轮教你如何打造少女肌肤吗?现在观看#人人都爱少女肌肤#教学视频就能从#innisfree#这里学到少女肌肤的底妆秘籍,还有机会赢取#悦诗风吟矿物质纯安动人粉底膏#哦!立刻猛击";

                 string jpgPath = Server.MapPath("") + "\\img\\bg1.jpg";

                 Sina.API.Statuses.Upload(weiboContent, GetBytesByImagePath(jpgPath));

                 //Sina.API.Statuses.Update(weiboContent);

             }
        }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: Rick1206/innisfree
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            //Response.Write( GetBytesByImagePath("/img/bg1.jpg"));

            if (Session["Token"] == null)
            {
                //string cusCallbackUrl = CallbackUrl + "?point=1";

                OAuth myoauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, CallbackUrl);

                String authUrl = myoauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);

                Response.Redirect(authUrl);
            }
            else
            {
                Sina = new Client(new OAuth(AppKey, AppSecret, Session["Token"].ToString(), null));
                //用cookie里的accesstoken来实例化OAuth,这样OAuth就有操作权限了

                UserID = Sina.API.Account.GetUID();
                string weiboContent = "想让韩国国宝级彩妆大师朴泰轮教你如何打造少女肌肤吗?现在观看#人人都爱少女肌肤#教学视频就能从#innisfree#这里学到少女肌肤的底妆秘籍,还有机会赢取#悦诗风吟矿物质纯安动人粉底膏#哦!立刻猛击";

                string jpgPath = Server.MapPath("") + "\\img\\bg1.jpg";

                Sina.API.Statuses.Upload(weiboContent, GetBytesByImagePath(jpgPath));

                //Sina.API.Statuses.Update(weiboContent);
            }
        }
コード例 #3
0
ファイル: Authorize.cs プロジェクト: 964968324/MyWeiBo
 /*
      * 正常的流程或Web流程:
      * 1. 获取授权地址
      * 2. 访问授权地址
      * 3. 授权成功后自动跳转至callback指定的网站,并获得code
      * 4. 通过code换取access token
      */
 public static void StartAuth(string Appkey,string Appsecert,string callbackURL)
 {
     oauth = new NetDimension.Weibo.OAuth(Appkey ,Appsecert , callbackURL );
     string  url = oauth.GetAuthorizeURL( ResponseType.Code);//根据授权方法,获得授权地址。
     System.Diagnostics.Process.Start(url);//模拟弹窗,Console方式直接打开了浏览器,Web项目可以根据需求来使用iframe、新窗口等打开此页面。
     //打开浏览器,进行授权流程,之后会跳转到callback指定的网址,并获得code
 }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string cusCallbackUrl = CallbackUrl + "?point=1";

                OAuth oauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, cusCallbackUrl);

                if (Session["Token"] != null)
                {
                    string token    = (string)Session["Token"];
                    OAuth  newoauth = new OAuth(AppKey, AppSecret, token, "");

                    NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(newoauth);



                    String uid = Sina.API.Account.GetUID();
                    NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(uid, null);


                    //NetDimension.Weibo.Entities.user.Collection userFriends = new NetDimension.Weibo.Entities.user.Collection();

                    Session["wid"] = uid;

                    Response.Redirect(CallbackUrl);
                }
                else
                {
                    String mycode = Request.QueryString["code"];

                    if (mycode == String.Empty || mycode == null)
                    {
                        String authUrl = oauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);
                        Response.Redirect(authUrl);
                    }
                    else
                    {
                        AccessToken accessToken = oauth.GetAccessTokenByAuthorizationCode(mycode);

                        NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(oauth);
                        String uid = Sina.API.Account.GetUID();
                        //Response.Write(uid);
                        Session["wid"] = Sina.API.Account.GetUID();


                        Response.Redirect(CallbackUrl);

                        Session["Token"] = accessToken.Token;
                    }
                }
            }
        }
コード例 #5
0
ファイル: Login.aspx.cs プロジェクト: Rick1206/innisfree
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string cusCallbackUrl = CallbackUrl + "?point=1";

                OAuth oauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, cusCallbackUrl);

                if (Session["Token"] != null)
                {
                    string token = (string)Session["Token"];
                    OAuth newoauth = new OAuth(AppKey, AppSecret, token, "");

                    NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(newoauth);

                    String uid = Sina.API.Account.GetUID();
                    NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(uid, null);

                    //NetDimension.Weibo.Entities.user.Collection userFriends = new NetDimension.Weibo.Entities.user.Collection();

                    Session["wid"] = uid;

                    Response.Redirect(CallbackUrl);

                }
                else
                {
                    String mycode = Request.QueryString["code"];

                    if (mycode == String.Empty || mycode == null)
                    {
                        String authUrl = oauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);
                        Response.Redirect(authUrl);
                    }
                    else
                    {

                        AccessToken accessToken = oauth.GetAccessTokenByAuthorizationCode(mycode);

                        NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(oauth);
                        String uid = Sina.API.Account.GetUID();
                        //Response.Write(uid);
                        Session["wid"] = Sina.API.Account.GetUID();

                        Response.Redirect(CallbackUrl);

                        Session["Token"] = accessToken.Token;

                    }
                }
            }
        }
コード例 #6
0
ファイル: PatnerLogin.ascx.cs プロジェクト: Kjubo/luckysign
        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/ThirdLogin.xml")));
            XmlNode node = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID");
            XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key");
            string returnurl = AppConfig.HomeUrl() + "Passport/ThirdLogin.aspx";
            if (url != "")
            {
                returnurl += "?url=" + url;
            }
            var oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, returnurl);

            //第一步获取新浪授权页面的地址
            var authUrl = oauth.GetAuthorizeURL(); //VS2008需要指定全部4个参数,这里是VS2010等支持“可选参数”的开发环境的写法
            // 第二步访问这个地址。
            Response.Redirect(authUrl);
        }
コード例 #7
0
        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/ThirdLogin.xml")));
            XmlNode node      = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID");
            XmlNode node1     = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key");
            string  returnurl = AppConfig.HomeUrl() + "Passport/ThirdLogin.aspx";

            if (url != "")
            {
                returnurl += "?url=" + url;
            }
            var oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, returnurl);

            //第一步获取新浪授权页面的地址
            var authUrl = oauth.GetAuthorizeURL(); //VS2008需要指定全部4个参数,这里是VS2010等支持“可选参数”的开发环境的写法

            // 第二步访问这个地址。
            Response.Redirect(authUrl);
        }
コード例 #8
0
ファイル: UserController.cs プロジェクト: dannywj/MyHeart
        public JsonResult OAuthInit()
        {
            JsonResult jr = new JsonResult();
            jr.ContentType = "text/json";
            jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            try
            {
                Client Sina = null;
                OAuth oauth = new OAuth(CnfgConst.Sina_AppKey, CnfgConst.Sina_AppSecret, CnfgConst.Sina_CallbackUrl);

                Sina = new Client(oauth); //用cookie里的accesstoken来实例化OAuth,这样OAuth就有操作权限了
                //if (!string.IsNullOrEmpty(code))//暂时无法获取到传回的URL
                //{
                //    var token = oauth.GetAccessTokenByAuthorizationCode(code);
                //    string accessToken = token.Token;

                //    Response.Cookies["AccessToken"].Value = accessToken;
                //    jr.Data = new { isSuccess = true };
                //    //Response.Redirect("Default.aspx");
                //}
                //else
                {
                    string url = oauth.GetAuthorizeURL();
                    jr.Data = new { isSuccess = false, url = url };
                }
                return jr;

            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #9
0
ファイル: Login.aspx.cs プロジェクト: noikiy/lihongtu
    protected void SinaOAuthRequest()
    {
        string appKey = ConfigurationManager.AppSettings["AppKey"];
        string appSecret = ConfigurationManager.AppSettings["AppSecret"];
        string callbackUrl = ConfigurationManager.AppSettings["CallbackUrl"] ;
        OAuth oauth = new OAuth(appKey, appSecret, callbackUrl);

        Sina = new Client(oauth);
        if (!IsPostBack)
        {

            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                AccessToken token = oauth.GetAccessTokenByAuthorizationCode(Request.QueryString["code"]);
                string accessToken = token.Token;

                cookie["AccessToken"] = accessToken;

                Response.Redirect("SinaDefaultV2.aspx"+Utils.UrlEncode("?ReturnUrl="+ReturnURL) );
            }
            else
            {
                string url = oauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);
                authUrl.NavigateUrl = url;
            }

        }
    }