服务:新浪微博功能分类:社交支持平台:Android运行环境:Eclipse开发语言:Java开发工具:Eclipse源码大小:6.90MB源码下载地址:http://download.51cto.com/data/1977280源码介绍自己做的一个小项目,基本实现了新浪微博提供的接口的主要功能,授权登录、发送、转发、评论、搜索等。您也可以在没有网络的情况下读取数据库数据进行离线浏览。整个项目中可能存在一些错误。希望童鞋们找到可以联系我!一起学习!源码运行截图转发,评论微博文字授权登录搜索用户发送微博评论查看源码片段publicclassHomefragmenttextendsFragmentimplementsOnRefreshLoadingMoreListener{privateContextcontext;privateDragListViewlv;privateMyviewadapteradapter;privateOauth2AccessTokenmAccessToken;/**微博信息列表*/privateStatusListstatuses;/**获取微博信息API*/privateStatusesAPImStatusesAPI;Listmystatuslist;ContentValuesvalues;StringTABLE_NAME="weibo";SQLiteDatabasedatabase;Handlerhandler=newHandler(){publicvoidhandleMessage(Messagemsg){switch(msg.what){case0:statuses=(StatusList)msg??.obj;break;case1:statuses=(StatusList)msg.obj;break;case2:StatusListstatuse=(StatusList)msg.obj;statuses.statusList.addAll(statuses.statusList.size(),statuse.statusList);break;default:break;}adapter=newMyviewadapter(context,statuses,null);lv.setAdapter(adapter);}};publicHomefragment(Contextcontext){super();this.context=context;}@OverridepublicViewonCreateView(LayoutInflaterinf后来,ViewGroupcontainer,BundlesavedInstanceState){Viewview=inflater.inflate(R.layout.fragment_home,container,false);getinformation(getActivity()。getApplicationContext());lv=(DragListView)view.findViewById(R.id.dragListView1);//lv=(MyView)view.findViewById(R.id.myview1);lv.getFooterViewsCount();lv.setOnCreateContextMenuListener(this);lv.setOnRefreshListener(this);if(!GlobalstaiticData.connect){database=Databaseinit.initdatabase(context);select();adapter=newMyviewadapter(context,null,mystatuslist);lv.setAdapter(adapter);Log.i("123",mystatuslist.size()+"");}returnview;}privatevoidselect(){mystatuslist=newArrayList();Cursorcursor=database.query(TABLE_NAME,null,null,null,null,null,null);for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){Stringscreen_name=cursor.getString(cursor.getColumnIndex("screen_name"));Stringsource=cursor.getString(cursor.getColumnIndex("source"));Stringtext=cursor.getString(cursor.getColumnIndex("text"));Stringretext=cursor.getString(cursor.getColumnIndex("retext"));Stringidstr=cursor.getString(cursor.getColumnIndex("idstr"));byte[]head=cursor.getBlob(cursor.getColumnIndex("head"));Mystatusmystatus=newMystatus(screen_name,source,text,retext,idstr,head);mystatuslist.add(mystatus);}}privatevoidgetinformation(Contextcontext){//获取当前保存的TokenmAccessToken=AccessTokenKeeper.readAccessToken(context);//实例化statusAPImStatusesAPI=newStatusesAPI(mAccessToken);if(mAccessToken!=null&&mAccessToken.isSessionValid()){mStatusesAPI.friendsTimeline(0L,0L,10,1,false,0,false,mListener);}else{Toast.makeText(context,"Token不存在",Toast.LENGTH_LONG).show();}}/***微博OpenAPI回调接口*/privateRequestListenermListener=newRequestListener(){@OverridepublicvoidonComplete(Stringresponse){Log.i("json",response);if(!TextUtils.isEmpty(response)){if(response.startsWith("{\"statuses\"")){//调用StatusList#parse将字符串解析成微博列表对象StatusListstatuses=StatusList.parse(response);Messagemsg=newMessage();msg.what=0;msg.obj=statuses;handler.sendMessage(msg);if(statuses!=null&&statuses.total_number>0){Toast.makeText(getActivity().getApplicationContext(),"获取微博信息流成功,条数:"+statuses.statusList.size(),Toast.LENGTH_LONG).show();}}elseif(response.startsWith("{\"created_at\"")){//调用Status#parse将字符串解析成微博对象Statusstatus=Status.parse(response);Toast.makeText(getActivity().getApplicationContext(),"发微博成功,id="+status.id,Toast.LENGTH_LONG).show();}else{Toast.makeText(getActivity().getApplicationContext(),响应,Toast.LENGTH_LONG).show();}}}@OverridepublicvoidonWeiboException(微博异常一){//ErrorInfoinfo=ErrorInfo.parse(e.getMessage());//Toast.makeText(getActivity().getApplicationContext(),//info.toString(),Toast.LENGTH_LONG).show();}};privatevoidgetinformationmore(Contextcontext){//获取当前保存的TokenmAccessToken=AccessTokenKeeper.readAccessToken(context);//实例化statusAPImStatusesAPI=newStatusesAPI(mAccessToken);if(mAccessToken!=null&&mAccessToken.isSessionValid()){mStatusesAPI.friendsTimeline(0L,0L,5,2,false,0,false,moreListener);}else{Toast.makeText(context,"令牌不存在",Toast.LENGTH_LONG).show();}}/***微博OpenAPI回调接口*/privateRequestListenermoreListener=newRequestListener(){@OverridepublicvoidonComplete(Stringresponse){Log.i("json",response);if(!TextUtils.isEmpty(response)){if(response.startsWith("{\"statuses\"")){//调用StatusList#parse将字符串解析成微博列表对象StatusListstatuses=StatusList.parse(response);Messagemsg=newMessage();msg.what=2;msg.obj=statuses;handler.sendMessage(msg);lv.onLoadMoreComplete(false);if(statuses!=null&&statuses.total_number>0){Toast.makeText(getActivity().getApplicationContext(),"获取微博信息流成功,条数:"+statuses.statusList.size(),Toast.LENGTH_LONG).show();}}elseif(response.startsWith("{\"created_at\"")){//调用Status#parse将字符串解析成微博对象Statusstatus=Status.parse(response);Toast.makeText(getActivity().getApplicationContext(),"发送微博成功,id="+status.id,Toast.LENGTH_LONG).show();}else{Toast.makeText(getActivity().getApplicationContext(),response,Toast.LENGTH_LONG).show();}}}@OverridepublicvoidonWeiboException(WeiboExceptione){//ErrorInfoinfo=ErrorInfo.parse(e.getMessage());//Toast.makeText(getActivity().getApplicationContext(),//info.toString(),Toast.LENGTH_LONG).show();}};privatevoidgetinformationupdata(Contextcontext){//获取当前保存的TokenmAccessToken=AccessTokenKeeper.readAccessToken(context);////实例化statusAPImStatusesAPI=newStatusesAPI(mAccessToken);if(mAccessToken!=null&&mAccessToken.isSessionValid()){mStatusesAPI.friendsTimeline(0L,0L,10,1,false,0,false,myListener);}else{Toast.makeText(上下文,"令牌不存在",Toast.LENGTH_LONG).show();}}/****微博OpenAPI回调接口*/privateRequestListenermyListener=newRequestListener(){@OverridepublicvoidonComplete(Stringresponse){if(!TextUtils.isEmpty(response)){if(response.startsWith("{\"statuses\"")){//调用//StatusList#parse//将字符串解析成微博列表对象StatusListstatuses=StatusList.parse(response);Messagemsg=newMessage();msg.what=1;msg.obj=statuses;handler.sendMessage(msg);lv.onRefreshComplete();if(statuses!=null&&statuses.total_number>0){Toast.makeText(getActivity().getApplicationContext(),"获取微博信息流成功,条数:"+statuses.statusList.size(),Toast.LENGTH_LONG).show();}}elseif(response.startsWith("{\"created_at\"")){//调用//Status#parse//将字符串解析成微博对象Statusstatus=Status.parse(response);Toast.makeText(getActivity().getApplicationContext(),"发微博成功,id="+status.id,Toast.LENGTH_LONG).show();}else{Toast.makeText(getActivity().getApplicationContext(),response,Toast.LENGTH_LONG).show();}}}@OverridepublicvoidonWeiboException(WeiboExceptionne){//ErrorInfoinfo=ErrorInfo.parse(e.getMessage());//Toast.makeText(getActivity().getApplicationContext(),//info.toString(),Toast.LENGTH_LONG).show();}};@OverridepublicvoidonCreateContextMenu(ContextMenumenu,Viewv,ContextMenuInfomenuInfo){menu.setHeaderTitle("更多操作");//添加菜单项menu.add(0,Menu.FIRST,0,"转发");menu.add(0,Menu.FIRST+1,0,"评论");super.onCreateContextMenu(menu,v,menuInfo);}@OverridepublicbooleanonContextItemSelected(MenuItemitem){AdapterContextMenuInfo=(AdapterContextMenuInfo)item.getMenuInfo();switch(item.getItemId()){case1:Intentintent1=newIntent(getActivity(),RepostActivity.class);intent1.putExtra("status",statuses.statusList.get(info.position));startActivity(intent1);break;case2:Intentintent=newIntent(getActivity(),CommentsomebadyActivity.class);intent.putExtra("id",statuses.statusList.get(info.position).idstr);Log.i("评论","微博:"+statuses.statusList.get(信息。position).idstr);startActivity(intent);break;default:break;}//Toast.makeText(getActivity().getApplicationContext(),//"第几项:"+item.getItemId()+"的第一个:"+info.position,//Toast.LENGTH_LONG).show();returnsuper.onContextItemSelected(item);}/****下拉刷新*/@OverridepublicvoidonRefresh(){getinformationupdata(context);}/****点击加载更多*/@OverridepublicvoidonLoadMore(){getinformationmore(context);}}源码下载地址:http://down.51cto.com/data/1977280