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

 

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

 

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

目前提供的SDK:

 

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

 

当前已实现的功能:

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

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

 

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

 

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

 

API字段说明

 

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

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

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

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

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<appSettings>
    
<add key="AppKey" value="3476523072"/>
    
<add key="AppSecret" value="3c909770efa6865fd5843a564545826d"/>
  
</appSettings>
</configuration>

 

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

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

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

        
internal static string UserName { getset; }
        
internal static string Password { getset; }
        
internal static string UserNamePassword { getset; }

        
internal static int ID { getset; }

        
internal static string ScreenName { getset; }

        
internal static string Name { getset; }

        
internal static int Province { getset; }

        
internal static int City { getset; }

        
internal static string Location { getset; }

        
internal static string Description { getset; }

        
internal static string Url { getset; }

        
internal static string ProfileImageUrl { getset; }

        
internal static string Domain { getset; }

        
internal static string Gender { getset; }

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

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

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

        
internal static int FavouritesCount { getset; }

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

        
internal static bool Following { getset; }

        
internal static bool Verified { getset; }

        
internal static bool AllowAllActMsg { getset; }

        
internal static bool GeoEnabled { getset; }

    }
}

相关文章:

  • 2021-10-26
  • 2022-03-03
  • 2021-12-07
  • 2021-11-17
猜你喜欢
  • 2021-11-25
  • 2021-12-11
  • 2021-11-21
  • 2021-04-02
  • 2021-04-29
  • 2021-12-10
相关资源
相似解决方案