这个接口已经出来一段时间了,下面的例子用Axis生成代理程序,然后调用其中的几个接口
1 生成代理的过程就不多说了 ,
大家自己弄,我使用的是 Eclispe 3.3 + Axis的。
生成的极其简单的过程请看这里 http://www.java2000.net/viewthread.jsp?tid=4682
2 使用回复功能的测试
ForumAPISoapProxy proxy
=
new
ForumAPISoapProxy();
Identity id = new Identity( " java2000_net " , " XXXXXXXXXX " );
Reply reply = new Reply();
reply.setBody( " 老紫竹测试回复 " );
reply.setForumId( " a3049f56-b572-48f5-89be-4797b70d71cd " );
reply.setTopicUrl( " http://topic.csdn.net/u/20080429/06/0d07606a-c3d4-4ad8-84af-8722215ea58b.html " );
reply.setEditor(EditorType.UBB);
ErrorHolder eHolder = new ErrorHolder();
BooleanHolder bHolder = new BooleanHolder();
LongHolder lHolder = new LongHolder();
IntHolder iHolder = new IntHolder();
proxy.reply(id, reply, bHolder, eHolder, lHolder, iHolder);
System.out.println(bHolder.value);
System.out.println(eHolder.value.getErrInfo());
System.out.println(lHolder.value);
System.out.println(iHolder.value);
Identity id = new Identity( " java2000_net " , " XXXXXXXXXX " );
Reply reply = new Reply();
reply.setBody( " 老紫竹测试回复 " );
reply.setForumId( " a3049f56-b572-48f5-89be-4797b70d71cd " );
reply.setTopicUrl( " http://topic.csdn.net/u/20080429/06/0d07606a-c3d4-4ad8-84af-8722215ea58b.html " );
reply.setEditor(EditorType.UBB);
ErrorHolder eHolder = new ErrorHolder();
BooleanHolder bHolder = new BooleanHolder();
LongHolder lHolder = new LongHolder();
IntHolder iHolder = new IntHolder();
proxy.reply(id, reply, bHolder, eHolder, lHolder, iHolder);
System.out.println(bHolder.value);
System.out.println(eHolder.value.getErrInfo());
System.out.println(lHolder.value);
System.out.println(iHolder.value);
3 自动发贴和结贴的代码
/**
* 发帖和结贴的测试
* @param username 用户名
* @param password 密码
* @param message 发帖的信息
* @param forumId 论坛的编号
*/
public void post(String username, String password, String message, String forumId) {
try {
ForumAPISoapProxy proxy = new ForumAPISoapProxy();
Identity id = new Identity(username, password);
Post post = new Post();
post.setBody(message);
post.setSubject(message);
post.setEditor(EditorType.UBB);
post.setForumId(forumId);
post.setPoint( 0 );
post.setIsAskExpert( false );
post.setTag( "" );
ErrorHolder eHolder = new ErrorHolder();
BooleanHolder bHolder = new BooleanHolder();
StringHolder sHolder = new StringHolder();
proxy.post(id, post, bHolder, eHolder, sHolder);
System.out.println(sHolder.value);
// 下面是把这个帖子结了
proxy.checkOutTopic(id,sHolder.value,forumId, new net.csdn.www.ReplyPoint[ 0 ],bHolder,eHolder);
System.out.println(bHolder.value);
} catch (Exception ex) {
ex.printStackTrace();
}
}
* 发帖和结贴的测试
* @param username 用户名
* @param password 密码
* @param message 发帖的信息
* @param forumId 论坛的编号
*/
public void post(String username, String password, String message, String forumId) {
try {
ForumAPISoapProxy proxy = new ForumAPISoapProxy();
Identity id = new Identity(username, password);
Post post = new Post();
post.setBody(message);
post.setSubject(message);
post.setEditor(EditorType.UBB);
post.setForumId(forumId);
post.setPoint( 0 );
post.setIsAskExpert( false );
post.setTag( "" );
ErrorHolder eHolder = new ErrorHolder();
BooleanHolder bHolder = new BooleanHolder();
StringHolder sHolder = new StringHolder();
proxy.post(id, post, bHolder, eHolder, sHolder);
System.out.println(sHolder.value);
// 下面是把这个帖子结了
proxy.checkOutTopic(id,sHolder.value,forumId, new net.csdn.www.ReplyPoint[ 0 ],bHolder,eHolder);
System.out.println(bHolder.value);
} catch (Exception ex) {
ex.printStackTrace();
}
}
4 获得用户信息的代码
/**
* 得到用户的信息
*
* @param username 认证的用户名
* @param password 认证的密码
* @param usernameGet 获取信息的用户名
*/
public void GetUserInfo(String username, String password, String usernameGet) {
try {
ForumAPISoapProxy proxy = new ForumAPISoapProxy();
Identity id = new Identity(username, password);
ErrorHolder eHolder = new ErrorHolder();
BooleanHolder bHolder = new BooleanHolder();
UserProfileHolder uHolder = new UserProfileHolder();
proxy.getUserProfile(id, usernameGet, bHolder, uHolder, eHolder);
if (bHolder.value) {
UserProfile u = uHolder.value;
System.out.println(u.getNickName());
System.out.println(u.getPoint());
System.out.println(u.getTechExpertPoint());
System.out.println(u.getNonTechExpertPoint());
TopForum[] fs = u.getTopForums();
for (TopForum f : fs) {
System.out.print(f.getForumId());
System.out.print( " " + f.getExpertPoint());
System.out.print( " " + f.getRank());
System.out.println();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
* 得到用户的信息
*
* @param username 认证的用户名
* @param password 认证的密码
* @param usernameGet 获取信息的用户名
*/
public void GetUserInfo(String username, String password, String usernameGet) {
try {
ForumAPISoapProxy proxy = new ForumAPISoapProxy();
Identity id = new Identity(username, password);
ErrorHolder eHolder = new ErrorHolder();
BooleanHolder bHolder = new BooleanHolder();
UserProfileHolder uHolder = new UserProfileHolder();
proxy.getUserProfile(id, usernameGet, bHolder, uHolder, eHolder);
if (bHolder.value) {
UserProfile u = uHolder.value;
System.out.println(u.getNickName());
System.out.println(u.getPoint());
System.out.println(u.getTechExpertPoint());
System.out.println(u.getNonTechExpertPoint());
TopForum[] fs = u.getTopForums();
for (TopForum f : fs) {
System.out.print(f.getForumId());
System.out.print( " " + f.getExpertPoint());
System.out.print( " " + f.getRank());
System.out.println();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
以上只是CSDN openAPI的简单使用步骤。其中的 GetUserInfo 部分已经应用于我的 【CSDN之路】的功能,用来记录用户在CSDN的积分历史。具体的请参考我的另一个文章 http://blog.csdn.net/java2000_net/archive/2008/05/06/2398006.aspx
<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>