100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android 启动新浪客户端 android开发新浪微博客户端

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

时间:2021-07-26 21:21:00

相关推荐

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

【实例简介】

【实例截图】

【核心代码】

package weibo4andriod.examples;

import java.io.*;

import .*;

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=.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;

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。