关于腾讯weibo获取头像的问题

在获取到自己的信息后

http://wiki.open.t.qq.com/index.php/%E5%B8%90%E6%88%B7%E7%9B%B8%E5%85%B3/%E8%8E%B7%E5%8F%96%E8%87%AA%E5%B7%B1%E7%9A%84%E8%AF%A6%E7%BB%86%E8%B5%84%E6%96%99

一直调用头像url 却获取不了!原来是要在后面加上头像的大小 如getHead(head+"/50");

下面给出获取头像的代码

 /**
    * 获取头像的Demo代码
    * @param head  注意加头像大小 /50 /100
    * @throws MalformedURLException
    * @throws IOException
    */
	private static void getHead(String head) throws MalformedURLException, IOException {
		
		System.out.println(head);
		HttpURLConnection hConnection=(HttpURLConnection) new URL(head).openConnection();
		hConnection.setRequestMethod("GET");
		System.out.println(hConnection.getResponseCode());
		if (hConnection.getResponseCode()==200) {
			InputStream inputStream=hConnection.getInputStream();
			byte[] data=readInputStream(inputStream);
			
			FileOutputStream fileOutputStream=new FileOutputStream("C://12.jpg");
			fileOutputStream.write(data);
			
			fileOutputStream.close();
		}
	
		
	}

	private static byte[] readInputStream(InputStream inputStream) throws IOException {
		// TODO Auto-generated method stub
		ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
		byte[] buffer=new byte[1024];
		int lenght=-1;
		
		while((lenght=inputStream.read(buffer))!=-1){
			 byteArrayOutputStream.write(buffer, 0, lenght);
		}
		  
		byteArrayOutputStream.close();
		inputStream.close();
		return byteArrayOutputStream.toByteArray();
	}





参考于http://www.dengguibao.cn/blog/110

关于腾讯微博API的几个注意事项
发表于 2011-01-15 18:02:33

前天花了一天的时间使用腾讯微博的API将腾讯微博搬到我的博客上面了,在使用API的过程中遇到了一些问题,最后通过了一些时间的摸索最后把问题解诀了,所以记下来,以备今后使用.

首先必须得搞清楚使用腾讯微博API的流程.

1 首先到open.t.qq.com得到app 和 key secure

2 然后下载开发者SDK

3 然后就可以根据API文档进行开发

开发中有以下问题值得注意

1 首先是根据app key 和app key secure得到请求token(request token)

2 然后使用请求token得到授权URL(authorized URL),然后根据授权URL进行授权

3 然后授权通过后得到访问token(access token)

4 使用访问令牌就可以通过请求得到腾讯微博的数据了.

下面是我得到的微博中"我的主页"的数据

01 info=>array {  //博文数组第
02         0=>array //第一条博文
03                 city_code=> //城市代码
04                 count=>0 //微博转发次数
05                 country_code=>1 //国家代码
06                 from=>Android //来自于  使用什么终端发的该微博
07                 geo=>0 // 发表者的地理信息
08                 head=>http://app.qlogo.cn/mbloghead/1de7885ef2d934446334  //微博的图像信息
09                 id=>14528056043030  //微博发布者的身份唯一ID
10                 image=>  //微博中的图片url列表
11                 isvip=>1  //是否官方认证 1 已认证 0 未认证
12                 location=>上海 //地区
13                 name=>xiucai  //名称
14                 nick=>子鼠-秀才  //昵称
15                 origtext=>团队还是非常年轻的…|| @peizihan: 真牛逼。  //原创内容(标题)
16                 province_code=>31  //省份代码
17                 self=>0  //是否自己发的博方  0 不是  1是
18  
19                 source=>array {  //因为不是自己发的微博所以该处的数据为数组,且为源微博的相关信息,内体意义如上
20                         city_code=>
21                         count=>7
22                         country_code=>
23                         from=>网页
24                         geo=>0
25                         head=>
26                         id=>3033097361641
27                         image=>array {
28                                 0=>http://app.qpic.cn/mblogpic/0a6a42e6eafa802963c4
29                         }
30                 isvip=>1
31                 location=>
32                 name=>huange
33                 nick=>莆田农民
34                 origtext=>数字看腾讯!!!!!@qqtech
35                 province_code=>
36                 self=>0
37                 status=>0
38                 text=>数字看腾讯!!!!!@qqtech
39                 timestamp=>1294728761
40                 type=>1 //1-原创发表、2-转载、3-私信 4-回复 5-空回 6-提及
41         }
42         status=>0 //微博状态 0-正常,1-系统删除 2-审核中 3-用户删除 4-根删除
43         text=>团队还是非常年轻的…|| @peizihan: 真牛逼。  //微博内容
44         timestamp=>1294732972  //发布时间截
45         type=>2  //当type=2时即上面的source数组为源微博
46 }

具体的意思都已经备注出来了,但是head字段要注意一下,head是发送微博者头像的URL,但是如果是访问这个URL是不可能得到头像的,刚开始我也不明白,然后看了微讯的官方的api文档里面也没有讲,然后我通过看官方微博的源代码发现所有的地址后面都加了一串数字.

头像分两类一类是大图像,即登陆微博右边显示的图像尺寸是100*100的,所以在上面的图像的url后面要加上100,还有一类就是发微博的左边显示的小头像尺寸是50*50的,所以在头像url后面要加上50,所谓的加50或100是指这样http://app.qlogo.cn/mbloghead/39cd8c536eb46a9bcea6/50





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值