/// <summary> /// 微博用户登录 /// </summary> private void login() { string appKey = System.Configuration.ConfigurationManager.AppSettings["appKey"]; string appSecret = System.Configuration.ConfigurationManager.AppSettings["appSecret"]; string userName = System.Configuration.ConfigurationManager.AppSettings["userName"]; string password = System.Configuration.ConfigurationManager.AppSettings["userPassword"]; OAuth oauth = new OAuth(appKey, appSecret); oauth.ClientLogin(userName, password); client = new Client(oauth); }
private void btnSendToWeibo_Click(object sender, EventArgs e) { OAuth oauth = new OAuth(appKey, appSecrect, callbackUrl); string passport = this.txtName.Text.Trim(); string password = this.txtPwd.Text.Trim(); //string accessToken = string.Empty; bool result = oauth.ClientLogin(passport, password); if (!result) { MessageBoxHelper.Show("微博登陆失败!"); return; } //好吧,授权至此应该成功了。下一步调用接口吧。 Client Sina = new Client(oauth); try { //.Net其他版本 string uid = Sina.API.Account.GetUID(); //获取UID //这里用VS2010的var关键字和可选参数最惬意了。 //如果用VS2005什么的你得这样写: //NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(uid,null); //如果用VS2008什么的也不方便,你得把参数写全: //var userInfo = Sina.API.Users.Show(uid,null); var userInfo = Sina.API.Users.Show(uid, null); Console.WriteLine("昵称:{0}", userInfo.ScreenName); Console.WriteLine("来自:{0}", userInfo.Location); //发条微博啥的 Image img = this.imageProcessPanel1.GetFinalImage(); //var statusInfo = Sina.API.Statuses.Update(string.Format("我是{0},我来自{1},我在{2}用《新浪微博开放平台API for .Net SDK》开发了一个小程序并发了这条微博,欢迎关注http://weibosdk.codeplex.com/", userInfo.ScreenName, userInfo.Location, DateTime.Now.ToShortTimeString()),0,0,""); var statusInfo = Sina.API.Statuses.Upload("测试内容"+System.DateTime.Now.ToLocalTime().ToString(), ImageHelper.GetBytesByImage(img), 0, 0, ""); //加个当前时间防止重复提交报错。 Console.WriteLine("微博已发送,发送时间:{0}", statusInfo.CreatedAt); MessageBoxHelper.Show("微博已发送"); } catch (WeiboException ex) { Console.WriteLine("出错啦!" + ex.Message); MessageBoxHelper.Show("出错啦!" + ex.Message); } Console.WriteLine("演示结束,按任意键继续..."); }
private static bool ClientLogin(OAuth o) { //Console.Write("微博账号:"); string passport = "*****@*****.**"; //Console.Write("登录密码:"); //ConsoleColor originColor = Console.ForegroundColor; //Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^ string password = "******"; //Console.ForegroundColor = originColor; //恢复前景颜色。 return o.ClientLogin(passport, password); }
/// <summary> /// 初始化Weibo /// </summary> /// <returns></returns> private string InitWeiboOAuth() { if (Session["AccessToken"] == null) { OAUTH = new OAuth(APPKEY, APPSECRET, RETURNURL); if (!OAUTH.ClientLogin(WEIBO_NAME, PASSWORD)) { return "授权登录失败,请重试。"; } else { Session["AccessToken"] = OAUTH.AccessToken; Sina = new Client(OAUTH); UserID = Sina.API.Entity.Account.GetUID(); return OAUTH.AccessToken; } } else { return (string)Session["AccessToken"]; } }
private static bool ClientLogin(OAuth o) { string passport = Properties.WeiboOAuth.Default.WeiboUser; string password = Properties.WeiboOAuth.Default.WeiboPassword; Console.WriteLine("username:"******"password:"******"******"); return o.ClientLogin(passport, password); }
private static bool ClientLogin(OAuth o) { string username="******"; string password="******"; return o.ClientLogin(username, password); }
private static bool ClientLogin(OAuth o) { return o.ClientLogin(passport, password); }
static OAuth Authorize(string passport, string password) { OAuth o = new OAuth(Properties.Settings.Default.Appkey, Properties.Settings.Default.AppSecrect, Properties.Settings.Default.CallbackUrl); if (!o.ClientLogin(passport, password)) { throw new Exception("认证失败"); } return o; }