/*����΢��
http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2
����΢���Ĺ���̫�࣬û��һһ����
*/
/*��ע ���в�������������Ļ�������ȫ���ַ�����Ҫ����URLencodeת�루���д�������в�������ת����Ѷ��Ҳ��һ����ҪURLencode��*/



/*��ȡ΢���û����·�����΢���б� 

�ӿڵ�ַ	https://api.weibo.com/2/statuses/user_timeline.json

*/

https://api.weibo.com/2/statuses/user_timeline.json?access_token=abcd&uid=�û�id
����
https://api.weibo.com/2/statuses/user_timeline.json?access_token=abcd&screen_name=�û��dz�
/*
���ظ�ʽΪjson ����utf-8
*/
{
    "statuses": [
        {
            "created_at": "Tue May 31 17:46:55 +0800 2011",
            "id": 11488058246,//	΢��ID 
            "text": "���ע��"��
            "source": "<a href=\"http://weibo.com\" rel=\"nofollow\">����΢��</a>",//����
			"thumbnail_pic":"",//����ͼƬ��ַ��û��ʱ�����ش��ֶ� �ж�ʱ��ע��
			"bmiddle_pic":"",//�еȳߴ�ͼƬ��ַ��û��ʱ�����ش��ֶ�
			"original_pic":"",//ԭʼͼƬ��ַ��û��ʱ�����ش��ֶ� 
            "favorited": false,
            "truncated": false,
            "in_reply_to_status_id": "",
            "in_reply_to_user_id": "",
            "in_reply_to_screen_name": "",
            "geo": null,
            "mid": "5612814510546515491",//΢��MID 
            "reposts_count": 8,//ת����
            "comments_count": 9,//������
            "annotations": [],
            "user": {
                "id": 1404376560,//΢���û�id
                "screen_name": "zaku",//�û��dz�
                "name": "zaku",
                "province": "11",
                "city": "5",
                "location": "���� ������",//����
                "description": "������ʮ�꣬��������ã�����˹������׳ʿ���κ���",//���
                "url": "http://blog.sina.com.cn/zaku",//����
                "profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",//Сͷ��50X50
                "domain": "zaku",
                "gender": "m",
                "followers_count": 1204,
                "friends_count": 447,
                "statuses_count": 2908,
                "favourites_count": 0,
                "created_at": "Fri Aug 28 00:00:00 +0800 2009",
                "following": false,
                "allow_all_act_msg": false,
                "remark": "",
                "geo_enabled": true,
                "verified": false,
                "allow_all_comment": true,
                "avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1",//��ͷ��180X180
                "verified_reason": "",
                "follow_me": false,
                "online_status": 0,
                "bi_followers_count": 215
            }
        },
        ...
    ],
    "previous_cursor": 0,                     // ��δ֧��
    "next_cursor": 11488013766,      // ��δ֧��
    "total_number": 81655
}

/*
����һ����΢��
https://api.weibo.com/2/statuses/update.json
���ݷ�ʽΪpost
*/
{
	"access_token":"",//
	"status":""//Ҫ������΢���ı����ݣ�������URLencode�����ݲ�����140�����֡�
}
/*���ش����ʽ����*/
{
    "created_at": "Tue May 31 17:46:55 +0800 2011",
    "id": 11488058246,//΢��id
    "text": "���ע��"��//����
    "source": "<a href=\"http://weibo.com\" rel=\"nofollow\">����΢��</a>",//����
	"thumbnail_pic":"",//����ͼƬ��ַ��û��ʱ�����ش��ֶ� �ж�ʱ��ע��
	"bmiddle_pic":"",//�еȳߴ�ͼƬ��ַ��û��ʱ�����ش��ֶ�
	"original_pic":"",//ԭʼͼƬ��ַ��û��ʱ�����ش��ֶ� 
    "favorited": false,
    "truncated": false,
    "in_reply_to_status_id": "",
    "in_reply_to_user_id": "",
    "in_reply_to_screen_name": "",
    "geo": null,
    "mid": "5612814510546515491",//MID΢��
    "reposts_count": 8,
    "comments_count": 9,
    "annotations": [],
    "user": {
        "id": 1404376560,//�û�id
        "screen_name": "zaku",//�û��dz�
        "name": "zaku",
        "province": "11",
        "city": "5",
        "location": "���� ������",
        "description": "������ʮ�꣬��������ã�����˹������׳ʿ���κ���",
        "url": "http://blog.sina.com.cn/zaku",
        "profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",//�û�ͷ���ַ50X50
        "domain": "zaku",
        "gender": "m",
        "followers_count": 1204,
        "friends_count": 447,
        "statuses_count": 2908,
        "favourites_count": 0,
        "created_at": "Fri Aug 28 00:00:00 +0800 2009",
        "following": false,
        "allow_all_act_msg": false,
        "remark": "",
        "geo_enabled": true,
        "verified": false,
        "allow_all_comment": true,
        "avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1",//�û�ͷ���ַ180X180
        "verified_reason": "",
        "follow_me": false,
        "online_status": 0,
        "bi_followers_count": 215
    }
}





/*����һ��ͼƬ΢��
https://upload.api.weibo.com/2/statuses/upload.json
���ݷ�ʽΪpost
*/
{
	"access_token":"",
	"status":"",
	"pic":binary,//	binary��ʽ���� Ҫ�ϴ���ͼƬ����֧��JPEG��GIF��PNG��ʽ��ͼƬ��СС��5M�� 
}

/*�������ݸ�ʽ����*/

{
    "created_at": "Tue May 31 17:46:55 +0800 2011",
    "id": 11488058246,//΢��id
    "text": "���ע��"��//����
    "source": "<a href=\"http://weibo.com\" rel=\"nofollow\">����΢��</a>",//����
	"thumbnail_pic":"",//����ͼƬ��ַ��û��ʱ�����ش��ֶ� �ж�ʱ��ע��
	"bmiddle_pic":"",//�еȳߴ�ͼƬ��ַ��û��ʱ�����ش��ֶ�
	"original_pic":"",//ԭʼͼƬ��ַ��û��ʱ�����ش��ֶ� 
    "favorited": false,
    "truncated": false,
    "in_reply_to_status_id": "",
    "in_reply_to_user_id": "",
    "in_reply_to_screen_name": "",
    "geo": null,
    "mid": "5612814510546515491",//MID΢��
    "reposts_count": 8,
    "comments_count": 9,
    "annotations": [],
    "user": {
        "id": 1404376560,//�û�id
        "screen_name": "zaku",//�û��dz�
        "name": "zaku",
        "province": "11",
        "city": "5",
        "location": "���� ������",
        "description": "������ʮ�꣬��������ã�����˹������׳ʿ���κ���",
        "url": "http://blog.sina.com.cn/zaku",
        "profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",//�û�ͷ���ַ50X50
        "domain": "zaku",
        "gender": "m",
        "followers_count": 1204,
        "friends_count": 447,
        "statuses_count": 2908,
        "favourites_count": 0,
        "created_at": "Fri Aug 28 00:00:00 +0800 2009",
        "following": false,
        "allow_all_act_msg": false,
        "remark": "",
        "geo_enabled": true,
        "verified": false,
        "allow_all_comment": true,
        "avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1",//�û�ͷ���ַ180X180
        "verified_reason": "",
        "follow_me": false,
        "online_status": 0,
        "bi_followers_count": 215
    }
}

/*����֧��ֱ����ͼƬurl����һ��ͼƬ΢��
https://api.weibo.com/2/statuses/upload_url_text.json
���ݷ�ʽΪpost
*/
{
	"access_token":"",
	"status":"",
	"url":"",//	ͼƬ��URL��ַ��������http��ͷ��  
}
/*���ش����ʽͬ��*/





/*��עһ���û�
https://api.weibo.com/2/friendships/create.json
���ݷ�ʽΪPOST
*/
{
	"access_token":""//
	"uid":""//��Ҫ��ע���û�ID�� 
	"screen_name":""//��Ҫ��ע���û��dzơ�
	//�û�ID���û��dz���ѡ��һ
}
/**����*/

{
    "id": 1404376560,//�û�id
    "screen_name": "zaku",//�û��dz�
    "name": "zaku",
    "province": "11",
    "city": "5",
    "location": "���� ������",
    "description": "������ʮ�꣬��������ã�����˹������׳ʿ���κ���",
    "url": "http://blog.sina.com.cn/zaku",
    "profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",
    "domain": "zaku",
    "gender": "m",
    "followers_count": 1204,
    "friends_count": 447,
    "statuses_count": 2908,
    "favourites_count": 0,
    "created_at": "Fri Aug 28 00:00:00 +0800 2009",
    "following": false,
    "allow_all_act_msg": false,
    "geo_enabled": true,
    "verified": false,
    "status": {
        "created_at": "Tue May 24 18:04:53 +0800 2011",
        "id": 11142488790,
        "text": "�ҵ�������ˡ�",
        "source": "<a href=\"http://weibo.com\" rel=\"nofollow\">����΢��</a>",
        "favorited": false,
        "truncated": false,
        "in_reply_to_status_id": "",
        "in_reply_to_user_id": "",
        "in_reply_to_screen_name": "",
        "geo": null,
        "mid": "5610221544300749636",
        "annotations": [],
        "reposts_count": 5,
        "comments_count": 8
    },
    "allow_all_comment": true,
    "avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1",
    "verified_reason": "",
    "follow_me": false,
    "online_status": 0,
    "bi_followers_count": 215
}

/*ȡ����עһ���û�
https://api.weibo.com/2/friendships/destroy.json
���ݷ�ʽΪPOST
*/
{
	"access_token":""//
	"uid":""//��Ҫ��ע���û�ID�� 
	"screen_name":""//��Ҫ��ע���û��dzơ�
	//�û�ID���û��dz���ѡ��һ
}
/*����ֵͬ��*/






/*
����΢�����󷵻ش�������
���ɹ��������û��������ֵ����������ʱ���֣��ж�ʱע��
*/
{
	"request" : "/statuses/home_timeline.json",
	"error_code" : "20502",
	"error" : "Need you follow uid."
}


/*��ע����MID������id��ת��function
var s=new SinaWeiboUtility();
 *s.id2mid() // idתmid
 *s.mid2id() // midתid
 ��Ȼ������MID��id��ת�Ľӿڲ������DZ��ش����ȽϿ�
 ���硰3z4efAo4lk����MID��Ϊ����base62ת����MID 
*/1651453804
function SinaWeiboUtility() {
    /**
    * 62�����ֵ�
    * @property {String}
    */
    this.str62keys = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    if (typeof (SinaWeiboUtility._initalized) == 'undefined') {
        /**
        * 10����ֵת��Ϊ62����
        * @param {String} int10 10����ֵ
        * @return {String} 62����ֵ
        */
        SinaWeiboUtility.prototype.int10to62 = function (int10) {
            var s62 = '';
            var r = 0;
            while (int10 != 0) {
                r = int10 % 62;
                s62 = this.str62keys.charAt(r) + s62;
                int10 = Math.floor(int10 / 62);
            }
            return s62;
        };
        /**
        * 62����ֵת��Ϊ10����
        * @param {String} str62 62����ֵ
        * @return {String} 10����ֵ
        */
        SinaWeiboUtility.prototype.str62to10 = function (str62) {
            var i10 = 0;
            for (var i = 0; i < str62.length; i++) {
                var n = str62.length - i - 1;
                var s = str62.substr(i, 1);  // str62[i]; �ַ��������鷽ʽ��ȡ��IE�²�֧��Ϊ��undefined��
                i10 += parseInt(this.str62keys.indexOf(s)) * Math.pow(62, n);
            }
            return i10;
        };
        /**
        * idת��Ϊmid
        * @param {String} id ΢��id���� "201110410216293360"
        * @return {String} ΢��mid���� "wr4mOFqpbO"
        */
        SinaWeiboUtility.prototype.id2mid = function (id) {
            if (typeof (id) != 'string') {
                return false; // id��ֵ�ϴ󣬱���Ϊ�ַ�����
            }
            var mid = '';

            for (var i = id.length - 7; i > -7; i = i - 7) //�������ǰ��7�ֽ�Ϊһ���ȡmid
            {
                var offset1 = i < 0 ? 0 : i;
                var offset2 = i + 7;
                var num = id.substring(offset1, offset2);

                num = this.int10to62(num);
                mid = num + mid;
            }

            return mid;
        };
        /**
        * midת��Ϊid
        * @param {String} mid ΢��mid���� "wr4mOFqpbO"
        * @return {String} ΢��id���� "201110410216293360"
        */
        SinaWeiboUtility.prototype.mid2id = function (mid) {
            var id = '';

            for (var i = mid.length - 4; i > -4; i = i - 4) //�������ǰ��4�ֽ�Ϊһ���ȡmid�ַ�
            {
                var offset1 = i < 0 ? 0 : i;
                var len = i < 0 ? parseInt(mid.length % 4) : 4;
                var str = mid.substr(offset1, len);

                str = this.str62to10(str).toString();
                if (offset1 > 0) //�����ǵ�һ�飬����7λ��0
                {
                    while (str.length < 7) {
                        str = '0' + str;
                    }
                }

                id = str + id;
            }
            return id;
        };

        /**
        * ��ʶ�����Ƿ��ʼ����������������prototype��ֻ��ִ��һ�μ��ɣ�����Ҫ���ظ������㡣��
        * @property {boolean}
        */
        SinaWeiboUtility._initalized = true;
    }
}





//mid ����תbase62	base62encode()
//mid base62ת����	base62encode()

var encTable = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',  
	'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',  
	'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',  
	'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',  
	'1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/');  
var decTable = new Array(256);  
for (i = 0; i < encTable.length; i++) {  
	decTable[encTable[i]] = i;  
}
function base62encode(str) {  
	value = "";  
	pos = 0, val = 0;  
	for ( var i = 0; i < str.length; i++) {  
		val = (val << 8) | (str.charCodeAt(i) & 0xFF);  
		pos += 8;  
		while (pos > 5) {  
			c = encTable[val >> (pos -= 6)];  
			value += c == 'i' ? "ia" : c == '+' ? "ib" : c == '/' ? "ic" : c;  
			val &= ((1 << pos) - 1);  
		}  
	}  
	if (pos > 0) {  
		value += encTable[val << (6 - pos)];  
		if (pos == 2) {  
			value += "==";  
		} else if (pos == 4) {  
			value += "=";  
		}  
	}  
	return value;  
}  
function base62decode(str) {  
	pos = 0, val = 0;  
	value = "";  
	for ( var i = 0; i < str.length; i++) {  
		c = str.charAt(i);  
		if (c == '=') {  
			break;  
		}  
		if (c == 'i') {  
			c = str.charAt(++i);  
			c = c == 'a' ? 'i' : c == 'b' ? '+' : c == 'c' ? '/' : str.charAt(--i);  
		}  
		val = (val << 6) | decTable[c];  
		pos += 6;  
		while (pos > 7) {  
			value += String.fromCharCode((val >> (pos -= 8)) & 0xFF);  
			val &= ((1 << pos) - 1);  
		}  
	}  
	return value;  
}