コード例 #1
0
		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);

		}
コード例 #2
0
		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("获取成功!");
			}

		}