新浪微博PC客户端(DotNet WinForm版)——功能实现分解介绍

上一篇:新浪微博PC客户端(DotNet WinForm版)—— 初探

 

说明一下:只是兴趣,并不是想发布为一个软件,说实在的,如果要作为一个软件发布,要做的工作还有很多。 

 

新浪微博API地址:http://open.t.sina.com.cn/wiki/index.php/API%E6%96%87%E6%A1%A3etcode=0。

目前提供的SDK:

 

  • 1 Adobe Air
  • 2 Flash SDK
  • 3 PHP
  • 4 C++
  • 5 C#
  • 6 Java SDK
  • 7 Python SDK
  • 8 Javascript SDK(JSSDK)
  • 9 iOS SDK
  • 10 OAuth Library

其它的不清楚,C#的还不完善,而且不是官方的。

 

当前已实现的功能:

 1、HTTP普通鉴权(Basic Authentication)的身份验证方式,说白了就是每次访问API都要发送帐 和密码,当然是不安全的,但是相比OAuth验证方式门槛要低的多。要使用OAuth验证方式可以去看下SDK。

===》account/verify_credentials 验证当前用户身份是否合法 

 

OAuth是一种国际通用的授权方式,它的特点是不需要用户在第三方应用输入用户名及密码。OAuth的技术说明可参看官方 站 http://oauth.net。学习和研究OAuth的意义不仅仅在于新浪围脖,而是对以后开发类似的项目非常有意义和价值(如果你还不知道OAuth授权方式)。

 

验证通过则返回用户的个人信息,参照下面的API字段说明。

 

API字段说明

  • status 微博信息内容
  • user 用户资料信息
  • comment 评论信息描述
  • direct_message 私信信息
  • 省份城市编码表

 

上一篇说了,API返回的结果格式有两种:XML和JSON,在调用API的时候可以指定。

这里我指定的是XML格式,实现代码如下:

登录窗体:FrmLogin.cs,可以看上一篇的截图。 

(1)把申请AppKey和AppSecret写到app.config 

</span> xml version=”1.0″ encoding=”utf-8″  gt;
< configuration >
  
< appSettings >
    
< add  key =”AppKey”  value =”3476523072″ />
    
< add  key =”AppSecret”  value =”3c909770efa6865fd5843a564545826d” />
  
</ appSettings >
</ configuration >

 

要申请AppKey,需要登录新浪围脖,然后在这个地址创建应用并生成: http://open.t.sina.com.cn/apps/new。

(2)创建了一个静态类,保存用户信息 

namespace  MBClient.Entities
{
    
///   <summary>
    
///  微博帐 资料
    
///   </summary>
     internal   class  UserInfo
    {
        
internal  UserInfo(){ }

        

internal   static   string  UserName {  get set ; }
        
internal   static   string  Password {  get set ; }
        
internal   static   string  UserNamePassword {  get set ; }

        

internal   static   int  ID {  get set ; }

        

internal   static   string  ScreenName {  get set ; }

        

internal   static   string  Name {  get set ; }

        

internal   static   int  Province {  get set ; }

        

internal   static   int  City {  get set ; }

        

internal   static   string  Location {  get set ; }

        

internal   static   string  Description {  get set ; }

        

internal   static   string  Url {  get set ; }

        

internal   static   string  ProfileImageUrl {  get set ; }

        

internal   static   string  Domain {  get set ; }

        

internal   static   string  Gender {  get set ; }

        

///   <summary>
        
///  粉丝数
        
///   </summary>
         internal   static   int  FollowersCount {  get set ; }

        

///   <summary>
        
///  关注数
        
///   </summary>
         internal   static   int  FriendsCount {  get set ; }

        

///   <summary>
        
///  微博数
        
///   </summary>
         internal   static   int  StatusesCount {  get set ; }

        

internal   static   int  FavouritesCount {  get set ; }

        

///   <summary>
        
///  微博帐 日期
        
///   </summary>
         internal   static   string  CreatedAt {  get set ; }

        

internal   static   bool  Following {  get set ; }

        

internal   static   bool  Verified {  get set ; }

        

internal   static   bool  AllowAllActMsg {  get set ; }

        

internal   static   bool  GeoEnabled {  get set ; }

    }
}

 

  

(3)调用API 

namespace  MBClient.API
{
    
internal   class  ReadDataBySinaAPI
    {
        
internal  ReadDataBySinaAPI() { }

        

///   <summary>
        
///  根据用户登录信息登录并读取用户信息到DataSet
        
///   </summary>
        
///   <param name=”url”> API URL (XML Format) http://api.t.sina.com.cn/account/verify_credentials.xmlource=AppKey </param>
    
///   <param name=”httpRequestMethod)”> HTTP请求方式:GET或POST </param>
        
///   <returns></returns>
         internal   static  DataSet ReadXMLDataToDataSet( string  url,  string  httpRequestMethod)
   &

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2010年11月8日
下一篇 2010年11月9日

相关推荐