基本信息
源码名称:抓取新浪微博好友动态(可参考读取浏览器参数代码)
源码大小:0.91M
文件格式:.rar
开发语言:C#
更新时间:2016-11-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

想抓取的话 需在 新浪开放平台申请appid appsecret等信息,否则可能会提示没权限

主要参考价值是:控制台(客户端)程序 打开 浏览器  并读取浏览器中的 url参数 code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;
using System.Diagnostics;
using NetDimension.OpenPlatform;
using System.Windows.Forms;
using SHDocVw;
using Microsoft.Win32;

namespace TestConsoleApplication
{
	class Program
	{
        private static bool first = true;
        private static bool firstEnter = true;
        private static Thread _th = null;
		static void Main(string[] args)
		{
			Console.Title = "新浪微博采集器";
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
            //Console.WriteLine("开放平台 for C# SDK DEMO");
            //Console.WriteLine("版权所有 (C) 新浪网云南频道林选臣 1997-2012 保留所有权利。");
			Console.WriteLine();
            //ResetIEDefaultBrowser();

			while (true)
			{
                _th = new Thread(SDKTest);
                Thread.Sleep(5 * 1000);
                _th.Start();
                if (firstEnter)
                {
                    //Console.Write("再来一次?[y/n]");
                    Console.Write("请先登录微博,在ie浏览器url上出现code时,按回车开始……");
                    if (Console.ReadKey().Key != ConsoleKey.Enter)
                    {
                        break;
                    }
                    Console.WriteLine();
                    firstEnter = false;
                }
			}
		}

        private static string key = "";
        private static string secret = "";
        private static string callback = "";
        private static bool isSina = true;
		private static void SDKTest()
		{
            if (first)
            {
                frmSettings SettingsDialog = new frmSettings();
                if (SettingsDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                key = SettingsDialog.txtKey.Text;
                secret = SettingsDialog.txtSecret.Text;
                callback = SettingsDialog.txtCallback.Text;
                isSina = SettingsDialog.rbSina.Checked;
                first = false;
            }

			OpenPlatformClient Client = null;

			if (isSina)
			{
				var sina = new SinaClient(key, secret, callback);
				Process.Start(sina.GetAuthorizeUrl());

                string code = "";
                SHDocVw.ShellWindows shellwindows = new SHDocVw.ShellWindows();
                foreach (InternetExplorer ie in shellwindows)
                {
                    string filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                    if (filename.Equals("iexplore"))
                    {
                        string str = ie.LocationURL.ToString();
                        if (str.IndexOf("?code") > 0)
                        {
                            code = str.Split('=')[1].ToString();
                            break;
                        }
                        //else SDKTest();  
                    }
                }

                if (code != "")
                {
                    try
                    {
                        Console.Write("输入Code:");
                        Console.Write(code);

                        sina.GetAccessTokenByAuthorizationCode(code);
                        Client = sina;
                        //Get例子
                        var result = Client.SendCommand("statuses/home_timelinre");
                        Console.WriteLine(result);

                        //Console.WriteLine();
                        ////发微博测试
                        //result = Client.SendCommand("statuses/update", RequestMethod.Post, 
                        //    new RequestParameter("status",string.Format("我累个擦!发表于{0}",DateTime.Now)));
                        ////发图片测试
                        //MemoryStream ms = new MemoryStream();
                        //Properties.Resource.Example.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        //result = Client.SendCommand("statuses/upload", RequestMethod.Post,
                        //    new RequestParameter("status", string.Format("我累个擦!传个图片。发表于{0}", DateTime.Now)),
                        //    new RequestParameter("pic", ms.GetBuffer()));
                        //ms.Close();
                    }
                    catch(Exception ex)
                    {
                        Log.LogMsg(ex.ToString());
                    }
                }

			}
			else
			{
				var qq = new TencentClient(key, secret, callback);
				Process.Start(qq.GetAuthorizeUrl());
				
				Console.Write("输入Code:");
				var code = Console.ReadLine();
				Console.Write("输入OpenID:");
				var openid = Console.ReadLine();
				qq.GetAccessTokenByAuthorizationCode(code);
				qq.OpenID = openid;
				Client = qq;
				//Get例子
				var result = Client.SendCommand("statuses/home_timeline");
				Console.WriteLine(result);
				Console.WriteLine();
				//发微博测试
				result = Client.SendCommand("t/add", RequestMethod.Post,
					new RequestParameter("content", string.Format("我累个擦!发表于{0}", DateTime.Now)));
				//发图片测试
				MemoryStream ms = new MemoryStream();
				Properties.Resource.Example.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
				result = Client.SendCommand("t/add_pic", RequestMethod.Post,
					new RequestParameter("content", string.Format("我累个擦!传个图片。发表于{0}", DateTime.Now)),
					new RequestParameter("pic", ms.GetBuffer()));
				ms.Close();
			}
		}


        //public static void UpdateSql(string sql)
        //{
        //    string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString();
        //    SqlConnection conn = new SqlConnection();
        //    conn.ConnectionString = strConn;

        //    try
        //    {
        //        conn.Open();
        //        SqlCommand cmd = new SqlCommand(sql, conn);
        //        cmd.ExecuteNonQuery();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.Message);
        //    }
        //    conn.Close();
        //}

        private static string TransDate(string strDate)
        {
            System.Globalization.CultureInfo cultureInfo =
            System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
            string format = "ddd MMM d HH:mm:ss zz00 yyyy";
            DateTime dt = DateTime.ParseExact(strDate, format, cultureInfo); // 将字符串转换成日期
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public static bool ResetIEDefaultBrowser()
        {
            string mainKey = @"http\shell\open\command";
            string nameKey = @"http\shell\open\ddeexec\Application";
            string IEPath = @"C:\Program Files\Internet Explorer\iexplore.exe";
            bool result = false;
            try
            {
                string value = string.Format("\"{0}\" -- \"%1\"", IEPath);
                RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(mainKey, true);
                regKey.SetValue("", value);
                regKey.Close();
                regKey = Registry.ClassesRoot.OpenSubKey(nameKey, true);
                regKey.SetValue("", "IExplore");
                regKey.Close();

                result = true;
            }
            catch
            {
            }
            return result;
        }


	}
}