public SinaWeiboTest() { console.info("等待用户授权..."); var openAuth = new SinaWeiboClient("1402038860", "62e1ddd4f6bc33077c796d5129047ca2", "http://qcyn.sina.com.cn"); var form = openAuth.GetAuthenticationForm(); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { console.info("用户授权成功!"); console.data("AccessToken={0}", openAuth.AccessToken); StartTest(openAuth); } else { console.error("用户授权失败!"); } }
public ActionResult GetAuthorizationState() { var settings = ConfigurationManager.AppSettings; var oauth = new SinaWeiboClient(settings["appKey"], settings["appSecret"], settings["callbackUrl"]); if (Request.Cookies["access_token"] == null || string.IsNullOrEmpty(Request.Cookies["access_token"].Value)) { return(Json(new { authorized = false }, JsonRequestBehavior.AllowGet)); } var accessToken = Request.Cookies["access_token"].Value; var uid = Request.Cookies["uid"].Value; oauth.AccessToken = accessToken; oauth.UID = uid; //较v2版的sdk,新的v3版sdk移除了所有的本地化api接口,因为新浪的接口变来变去,踩着滑板鞋也追不着他们魔鬼的步伐。 //因此v3版的调用方式改为直接填写官方api名称和传递官方文档中要求的参数的方式来调用,返回结果需要自行使用json接卸器解析。 var response = oauth.HttpGet("user/show.json", new { uid = uid }); return(Json(response.Content.ReadAsStringAsync().Result, JsonRequestBehavior.AllowGet)); }
public void Evaluate(int SpreadMax) { client_out.SliceCount = 1; succeed_out.SliceCount = 1; if (authorize_in.SliceCount > 0 && authorize_in[0] && app_key_in[0].Length > 0 && app_secret_in[0].Length > 0 && callback_url_in[0].Length > 0) { //weiboClient = new SinaWeiboClient("1402038860", "62e1ddd4f6bc33077c796d5129047ca2", "http://qcyn.sina.com.cn"); SinaWeiboClient weiboClient = new SinaWeiboClient(app_key_in[0], app_secret_in[0], callback_url_in[0]); AuthenticationForm form = weiboClient.GetAuthenticationForm(); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { client_out[0] = weiboClient; succeed_out[0] = true; FLogger.Log(LogType.Debug, "Authorize Succeed"); FLogger.Log(LogType.Debug, weiboClient.AccessToken); } else { client_out[0] = null; succeed_out[0] = false; FLogger.Log(LogType.Debug, "Authorize Failed"); } } }
public SinaClientLogin(string appkey, string appsecret, string callback_url, string access_token = "", string uid = "") { this._appkey = appkey; this._appsecret = appsecret; this._callback_url = callback_url; this._accessToken = access_token; this._uid = uid; this._openAuth = new SinaWeiboClient(this._appkey, this._appsecret, callback_url, access_token, uid); }
/// <summary> /// 封装一个方法来初始化OpenAuth客户端 /// </summary> /// <returns></returns> private SinaWeiboClient GetOpenAuthClient() { var accessToken = Session["access_token"] == null ? string.Empty : (string)Session["access_token"]; var uid = Request.Cookies["uid"] == null ? string.Empty : Request.Cookies["uid"].Value; var settings = ConfigurationManager.AppSettings; var client = new SinaWeiboClient(settings["appKey"], settings["appSecret"], settings["callbackUrl"], accessToken, uid); return(client); }
/// <summary> /// 通过回调返回的code进行授权 /// </summary> /// <param name="code">code</param> /// <returns></returns> public bool Authorized(string code) { this._openAuth.GetAccessTokenByCode(code); if (this._openAuth.IsAuthorized) { this.IsAuthorized = true; this._accessToken = this._openAuth.AccessToken; this._uid = this._openAuth.UID; this._openAuth = new SinaWeiboClient(this._appkey, this._appsecret, this._callback_url, this._accessToken, this._uid); } return(this._openAuth.IsAuthorized); }
private void StartTest(SinaWeiboClient openAuth) { Console.WriteLine("Press enter to post a weibo."); if (Console.ReadKey(true).Key == ConsoleKey.Enter) { PostStatus(openAuth); } Console.WriteLine("Press enter to get user's timeline."); if (Console.ReadKey(true).Key == ConsoleKey.Enter) { GetFrindTimeline(openAuth); } }
private void StartTest(SinaWeiboClient openAuth) { console.attention("按任意键发布一条文字微博"); Console.ReadKey(true); PostStatus(openAuth); console.attention("按任意键发布一条图片微博"); Console.ReadKey(true); PostImageStatus(openAuth); console.attention("按任意键获取最新微博"); Console.ReadKey(true); GetFrindTimeline(openAuth); }
public SinaWeiboTest() { Console.WriteLine("Waitting for user authentication..."); var openAuth = new SinaWeiboClient("1402038860", "62e1ddd4f6bc33077c796d5129047ca2", "http://qcyn.sina.com.cn"); Console.WriteLine("Please input your username:"******"Please input your password:"); string password = Console.ReadLine(); openAuth.DoLogin(username, password); StartTest(openAuth); }
private void PostStatus(SinaWeiboClient openAuth) { Console.WriteLine("post a weibo..."); var result = openAuth.HttpPost("statuses/update.json", new Dictionary <string, object> { { "status", string.Format("post from OpenAuth.Assist! @{0:HH:mm:ss}", DateTime.Now) } }); Console.WriteLine("{0}", result); if (result.IsSuccessStatusCode) { Console.WriteLine(result.Content.ReadAsStringAsync().Result); Console.WriteLine("success!"); } }
private void PostStatus(SinaWeiboClient openAuth) { console.info("发布一条微博..."); var result = openAuth.HttpPost("statuses/update.json", new Dictionary <string, object> { { "status", string.Format("发布自SinaWeiboSDK_V3@{0:HH:mm:ss}", DateTime.Now) } }); console.attention("{0}", result); if (result.IsSuccessStatusCode) { console.data(result.Content.ReadAsStringAsync().Result); console.info("发布成功!"); } }
public static string GetUserInfo(SinaWeiboClient sw, int tryTimes) { // 调用获取获取用户信息api // 参考:http://open.weibo.com/wiki/2/users/show string result = null;; while (result == null && tryTimes > 0) { var response = sw.HttpGet("users/show.json", new { //可以传入一个Dictionary<string,object>类型的对象,也可以直接传入一个匿名类。参数与官方api文档中的参数相对应 uid = sw.UID }); result = response.ToString(); tryTimes--; } return(result); }
private void PostImageStatus(SinaWeiboClient openAuth) { console.info("发布一条图片微博..."); var imgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"MrJSON-Production.png"); var result = openAuth.HttpPost("statuses/upload.json", new Dictionary <string, object> { { "status", string.Format("发布自SinaWeiboSDK_V3@{0:HH:mm:ss}", DateTime.Now) }, { "pic", new FileInfo(imgPath) } }); console.attention("{0}", result); if (result.IsSuccessStatusCode) { console.data(result.Content.ReadAsStringAsync().Result); console.info("发布成功!"); } }
private void GetFrindTimeline(SinaWeiboClient openAuth) { Console.WriteLine("get user's timeline..."); var result = openAuth.HttpGet("statuses/friends_timeline.json", new Dictionary <string, object> { { "count", 5 }, { "page", 1 }, { "base_app", 0 } }); Console.WriteLine("{0}", result); if (result.IsSuccessStatusCode) { Console.WriteLine(result.Content.ReadAsStringAsync().Result); Console.WriteLine("success!"); } }
private void GetFrindTimeline(SinaWeiboClient openAuth) { console.info("获取当前登录用户及其所关注用户的最新微博..."); var result = openAuth.HttpGet("statuses/friends_timeline.json", new Dictionary <string, object> { { "count", 5 }, { "page", 1 }, { "base_app", 0 } }); console.attention("{0}", result); if (result.IsSuccessStatusCode) { console.data(result.Content.ReadAsStringAsync().Result); console.info("获取成功!"); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //请自行修改appKey,appSecret和回调地址。winform的回调地址可以是一个随便可以访问的地址,貌似不可以访问的地址也是可以的,只要URL中带着Code就行 var client = new SinaWeiboClient("4257120060", "ad556a1a628e118e14ff19f00f1266c5", "http://www.zfcode.com"); //NetDimension.OpenAuth.Winform封装的一个登录窗口,主要远离就是个WebBrowser控件,然后在该控件的导航事件里面监测Url是不是带有Code,如果有就调用GetAccessTokenByCode var authForm = client.GetAuthenticationForm(); authForm.StartPosition = FormStartPosition.CenterScreen; //authForm.Icon = Properties.Resources.icon_form; if (authForm.ShowDialog() == DialogResult.OK) { Application.Run(new Form1(client)); } // Application.Run(new Form1()); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //请自行修改appKey,appSecret和回调地址。winform的回调地址可以是一个随便可以访问的地址,貌似不可以访问的地址也是可以的,只要URL中带着Code就行 var client = new SinaWeiboClient("1402038860", "62e1ddd4f6bc33077c796d5129047ca2", "http://qcyn.sina.com.cn"); //NetDimension.OpenAuth.Winform封装的一个登录窗口,主要远离就是个WebBrowser控件,然后在该控件的导航事件里面监测Url是不是带有Code,如果有就调用GetAccessTokenByCode var authForm = client.GetAuthenticationForm(); authForm.StartPosition = FormStartPosition.CenterScreen; authForm.Icon = Properties.Resources.icon_form; if (authForm.ShowDialog() == DialogResult.OK) { Application.Run(new Form1(client)); } }
private async void BtnSinaWeiboShare_Click(object sender, RoutedEventArgs e) { UmengLink link = new UmengLink(); link.Url = ViewModel.WallpaperUrl; link.Type = LinkType.Picture; link.Text = ViewModel.ImageArchive.GetCopyright(); UmengClient umengClient = new SinaWeiboClient(App.appkey); var res = await umengClient.ShareLinkAsync(link); if (res.Status == ShareStatus.Success) { SideToastHelper.Success(ResourcesHelper.ShareSuccess); } else { SideToastHelper.Error(ResourcesHelper.ShareFailed); } }
public async Task <bool> ShareToSinaWeiboAsync(byte[] image, string text) { if (image == null) { throw new ArgumentNullException(nameof(image)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } var client = new SinaWeiboClient(Constants.SinaWeiboAppKey, Constants.SinaWeiboAppSecret, Constants.SinaWeiboRedirectUri); var status = await client.ShareAsync(text, image); if (status.ErrorCode <= 0) { return(true); } else { throw new Exception(status.ErrorMessage); } }
public static void sendWeibo(SinaWeiboClient sw, string text, string picPath = null) { if (sw == null) { return; } if (string.IsNullOrEmpty(picPath)) { // 参考:http://open.weibo.com/wiki/2/statuses/update sw.HttpPost("statuses/update.json", new { status = text }); } else { FileInfo imageFile = new FileInfo(picPath); sw.HttpPost("statuses/upload.json", new { status = text, pic = imageFile //imgFile: 对于文件上传,这里可以直接传FileInfo对象 }); } }
public SinaHelper(string token) { client = new SinaWeiboClient(PlatConfig.SinaKey, PlatConfig.SinaSecret, PlatConfig.SinaCallBack, token); }
public WeiBo() { SiteSettings masterSettings = SettingsManager.GetMasterSettings(false); this.sinaweibo = new GetAuth().GetOpenAuthClient(masterSettings.Access_Token); }
public void ClearAuthorization() { var client = new SinaWeiboClient(Constants.SinaWeiboAppKey, Constants.SinaWeiboAppSecret, Constants.SinaWeiboRedirectUri); client.ClearAuthorization(); }
public ApiImpl(SinaWeiboClient client) { this.Client = client; }
public OpenApi(SinaWeiboClient client) { _api = new ApiImpl(client); }