android 启动新浪客户端,android开发新浪微博客户端

【实例简介】

【实例截图】

a07641c30650d3de619944894fbd4805.png

【核心代码】

package weibo4andriod.examples;

import java.io.*;

import java.net.*;

import weibo4andriod.Status;

import weibo4andriod.Weibo;

import weibo4andriod.http.ImageItem;

public class Upload {

public static void main(String args[]){

try{

System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);

System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);

Weibo weibo = new Weibo();

weibo.setToken(args[0], args[1]);

try{

byte[] content= readFileImage(args[2]);

System.out.println("content length:" content.length);

ImageItem pic=new ImageItem("pic",content);

String url1=java.net.URLEncoder.encode("穿梭,时光。回到,最初。然后,穿越。在穿越,穿越,回到500年前,大闹天宫。 ","UTF-8");

System.out.println("" url1);

Status status=weibo.uploadStatus(url1, pic);

System.out.println("Successfully upload the status to ["

status.getText() "].");

}

catch(Exception e1){

e1.printStackTrace();

}

}catch(Exception ioe){

System.out.println("Failed to read the system input.");

}

}

public static byte[] readFileImage(String filename)throws IOException{

BufferedInputStream bufferedInputStream=new BufferedInputStream(

new FileInputStream(filename));

int len =bufferedInputStream.available();

byte[] bytes=new byte[len];

int r=bufferedInputStream.read(bytes);

if(len !=r){

bytes=null;

throw new IOException("读取文件不正确");

}

bufferedInputStream.close();

return bytes;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值