/// <summary> /// 发送一条带图片的微博,未带图片路径,则发送文字微博 /// </summary> /// <param name="status">信息</param> /// <param name="img">图片虚拟路径</param> public string PostStatus(string status, string imgpath = "") { var imgFile = string.IsNullOrEmpty(imgpath) ? null : new FileInfo(function.VToP(imgpath)); string result = ""; HttpResponseMessage response = null; if (!client.IsAuthorized) { return("PostStatus:新浪未授权,无法发送消息"); } if (imgFile != null && imgFile.Exists) { // 调用发图片微博api // 参考:http://open.weibo.com/wiki/2/statuses/upload response = client.HttpPost("statuses/upload.json", new { status = status, pic = imgFile //imgFile: 对于文件上传,这里可以直接传FileInfo对象 }); } else { // 调用发微博api // 参考:http://open.weibo.com/wiki/2/statuses/update response = client.HttpPost("statuses/update.json", new { status = status }); } //400为Token不正确 if (response.IsSuccessStatusCode) { result = "发送成功," + response.Content.ReadAsStringAsync().Result; } else { result = "发送失败," + response.ToString(); } return(result); }
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对象 }); } }
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("发布成功!"); } }
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("发布成功!"); } }