日期:2014-05-18  浏览次数:20480 次

网站发布信息 同步到一些微博 网站 怎么写 如新浪微博等
在网上我找了个新浪微博同步的例子
C# code


  //1) 准备用户验证数据:  username是你的微博登录用户名,password是你的博客密码。
            string username = "********";
            string password = ""********";
            string usernamePassword = username + ":" + password;


            //2) 准备调用的URL及需要POST的数据:
            string url = "https://api.weibo.com/2/statuses/update.json";

            string news_title = "祝大家!龙年吉祥,天天开心!";
            string t_news = string.Format("{0},http://www.baidu.com", news_title);
            string data = "source=[color=#FF0000]2360366171[/color]&status=" + System.Web.HttpUtility.UrlEncode(t_news);

            //3)准备用于发起请求的HttpWebRequest对象:
            System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
            System.Net.HttpWebRequest httpRequest = webRequest as System.Net.HttpWebRequest;

            //4)准备用于用户验证的凭据: 
            System.Net.CredentialCache myCache = new System.Net.CredentialCache();
            myCache.Add(new Uri(url), "Basic", new System.Net.NetworkCredential(username, password));
            httpRequest.Credentials = myCache;
            httpRequest.Headers.Add("Authorization", "Basic " +
            Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(usernamePassword)));


            //5)发起POST请求: 
            httpRequest.Method = "POST";
            httpRequest.ContentType = "application/x-www-form-urlencoded";
            System.Text.Encoding encoding = System.Text.Encoding.ASCII;
            byte[] bytesToPost = encoding.GetBytes(data);
            httpRequest.ContentLength = bytesToPost.Length;
            System.IO.Stream requestStream = httpRequest.GetRequestStream();
            requestStream.Write(bytesToPost, 0, bytesToPost.Length);
            requestStream.Close();


            //6)获取服务端的响应内容:
            System.Net.WebResponse wr = httpRequest.GetResponse();
            System.IO.Stream receiveStream = wr.GetResponseStream();
            using (System.IO.StreamReader reader = new System.IO.StreamReader(receiveStream, System.Text.Encoding.UTF8))
            {
                string responseContent = reader.ReadToEnd();

            }





结果可以实现在我的页面点击按钮实现 我的微博发布信息,,,,
但是实现此功能新浪微博需要一个 app key (上面红色数字部分)是我手动去新浪平台添加应用给分配的 

当我将账号密码换掉后 却不能实现了 原因可能是app key不对 这样我写的网站那些会员登录 怎么能同步数据呢 难道还叫他自己去申请app key么  

这样的该怎么解决呢


------解决方案--------------------
看下官方的API

http://open.weibo.com/development