├── .gitingore ├── .DS_Store ├── test.jpg ├── emotions.go ├── suggestions_test.go ├── favorites_test.go ├── token.go ├── common_test.go ├── search_test.go ├── remind.go ├── tags_test.go ├── utils.go ├── trends.go ├── comments_test.go ├── users_test.go ├── weibo_test.go ├── users.go ├── common.go ├── account.go ├── search.go ├── tags.go ├── short_url.go ├── friendships_test.go ├── suggestions.go ├── account_test.go ├── comments.go ├── statuses_test.go ├── favorites.go ├── friendships.go ├── pool.go ├── README.md ├── statuses.go ├── fileds.go ├── weibo.go ├── .tags └── wiki.md /.gitingore: -------------------------------------------------------------------------------- 1 | push.sh 2 | *.sublime* 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiocode/weigo/HEAD/.DS_Store -------------------------------------------------------------------------------- /test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiocode/weigo/HEAD/test.jpg -------------------------------------------------------------------------------- /emotions.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | //通过id获取mid 4 | func (api *APIClient) get_statuses_querymid(params map[string]interface{}, result interface{}) error { 5 | return api.GET("emotions", params, result) 6 | } 7 | -------------------------------------------------------------------------------- /suggestions_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_GET_suggestions_statuses_reorder(t *testing.T) { 8 | // t.SkipNow() 9 | kws := map[string]interface{}{ 10 | "section": 60, 11 | } 12 | result := new(Topic) 13 | err := api.GET_suggestions_statuses_reorder(kws, result) 14 | debugCheckError(err) 15 | debugPrintln(*result) 16 | } 17 | -------------------------------------------------------------------------------- /favorites_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_GET_favorites(t *testing.T) { 8 | t.SkipNow() 9 | kws := map[string]interface{}{ 10 | "access_token": api.access_token, 11 | "source": api.app_key, 12 | } 13 | result := new(Favorites) 14 | err := api.GET_favorites(kws, result) 15 | debugCheckError(err) 16 | debugPrintln(*((*result.Favorites)[0]).Status) 17 | } 18 | -------------------------------------------------------------------------------- /token.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | type TokenInfo struct { 4 | UID int `json:"uid"` 5 | AppKey string `json:"appkey"` 6 | Scope string `json:"scope"` 7 | CreatedAt int `json:"create_at"` 8 | ExpireIn int `json:"expire_in"` 9 | } 10 | 11 | //获取一个token info 12 | func (api *APIClient) GET_token_info(params map[string]interface{}, result *TokenInfo) error { 13 | return api.Auth("get_token_info", params, result) 14 | } -------------------------------------------------------------------------------- /common_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_GET_common_get_province(t *testing.T) { 8 | t.SkipNow() 9 | kws := map[string]interface{}{ 10 | "country": "001", 11 | "access_token": api.access_token, 12 | "source": api.app_key, 13 | } 14 | result := new([]map[string]string) 15 | err := api.GET_common_get_province(kws, result) 16 | debugCheckError(err) 17 | debugPrintln(((*result)[0])) 18 | } 19 | -------------------------------------------------------------------------------- /search_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | import ( 9 | // "fmt" 10 | "testing" 11 | ) 12 | 13 | func Test_GET_search_topics(t *testing.T) { 14 | t.SkipNow() 15 | kws := map[string]interface{}{ 16 | "q": "肖申克的救赎", 17 | } 18 | result := new(Topic) 19 | err := api.GET_search_topics(kws, result) 20 | debugCheckError(err) 21 | debugPrintln(*result) 22 | } 23 | -------------------------------------------------------------------------------- /remind.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //获取某个用户的各种消息未读数 9 | func (api *APIClient) GET_remind_unread_count(params map[string]interface{}, result interface{}) error { 10 | return api.GET("remind/unread_count", params, result) 11 | } 12 | 13 | //对当前登录用户某一种消息未读数进行清零 14 | func (api *APIClient) POST_remind_set_count(params map[string]interface{}, result interface{}) error { 15 | return api.POST("remind/set_count", params, result) 16 | } 17 | -------------------------------------------------------------------------------- /tags_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_GET_tags(t *testing.T) { 8 | t.SkipNow() 9 | kws := map[string]interface{}{ 10 | "uid": "2684726573", 11 | } 12 | result := new([]map[string]interface{}) 13 | err := api.GET_tags(kws, result) 14 | debugCheckError(err) 15 | debugPrintln(((*result)[0]["weight"])) 16 | } 17 | 18 | func Test_GET_tags_tags_batch(t *testing.T) { 19 | t.SkipNow() 20 | kws := map[string]interface{}{ 21 | "uids": "2684726573", 22 | } 23 | result := new([]Tags) 24 | err := api.GET_tags_tags_batch(kws, result) 25 | debugCheckError(err) 26 | debugPrintln((*result)) 27 | } 28 | -------------------------------------------------------------------------------- /utils.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao 3 | * Email: xiocode@gmail.com 4 | * Github: github.com/xiocode 5 | * File: utils.go 6 | * Description: util 7 | */ 8 | 9 | package weigo 10 | 11 | import ( 12 | "fmt" 13 | "reflect" 14 | ) 15 | 16 | func checkError(err error) bool { 17 | if err != nil { 18 | return true 19 | } 20 | return false 21 | } 22 | 23 | func debugPrintln(message ...interface{}) { 24 | fmt.Println(message) 25 | } 26 | 27 | func debugTypeof(element interface{}) interface{} { 28 | return reflect.TypeOf(element) 29 | } 30 | 31 | func debugCheckError(err error) { 32 | if err != nil { 33 | debugPrintln(err) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /trends.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //返回最近一小时内的热门话题 9 | func (api *APIClient) GET_trends_hourly(params map[string]interface{}, result interface{}) error { 10 | return api.GET("trends/hourly", params, result) 11 | } 12 | 13 | //返回最近一天内的热门话题 14 | func (api *APIClient) GET_trends_daily(params map[string]interface{}, result interface{}) error { 15 | return api.GET("trends/daily", params, result) 16 | } 17 | 18 | //返回最近一周内的热门话题 19 | func (api *APIClient) GET_trends_weekly(params map[string]interface{}, result interface{}) error { 20 | return api.GET("searchtrends/weekly", params, result) 21 | } 22 | -------------------------------------------------------------------------------- /comments_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_GET_comments_show(t *testing.T) { 8 | t.SkipNow() 9 | kws := map[string]interface{}{ 10 | "id": "3551749023600582", 11 | } 12 | result := new(Comments) 13 | err := api.GET_comments_show(kws, result) 14 | debugCheckError(err) 15 | debugPrintln(len(*result.Comments)) 16 | } 17 | 18 | func Test_POST_comments_create(t *testing.T) { 19 | t.SkipNow() 20 | kws := map[string]interface{}{ 21 | "id": "3551749023600582", 22 | "comment": "Testing...Testing...", 23 | } 24 | result := new(Comment) 25 | err := api.POST_comments_create(kws, result) 26 | debugCheckError(err) 27 | debugPrintln(*result) 28 | } 29 | -------------------------------------------------------------------------------- /users_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func Test_GET_users_show(t *testing.T) { 13 | t.SkipNow() 14 | kws := map[string]interface{}{ 15 | "uid": "2684726573", 16 | } 17 | result := new(User) 18 | err := api.GET_users_show(kws, result) 19 | debugCheckError(err) 20 | debugPrintln(*result) 21 | } 22 | 23 | func Test_GET_users_counts(t *testing.T) { 24 | t.SkipNow() 25 | kws := map[string]interface{}{ 26 | "uids": "1580095602,2684726573", 27 | } 28 | result := new([]UserCounts) 29 | err := api.GET_users_counts(kws, result) 30 | debugCheckError(err) 31 | debugPrintln(*result) 32 | } 33 | -------------------------------------------------------------------------------- /weibo_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "testing" 7 | ) 8 | 9 | func TestGetAuthorizeUrl(t *testing.T) { 10 | t.SkipNow() 11 | authorize_url, err := api.GetAuthorizeUrl(nil) 12 | if err != nil { 13 | fmt.Println(err) 14 | } 15 | fmt.Println(authorize_url) 16 | } 17 | 18 | func TestRequestAccessToken(t *testing.T) { 19 | t.SkipNow() 20 | var result map[string]interface{} 21 | err := api.RequestAccessToken("1fdaa295b73d2a9568e284383ced5e9e", &result) 22 | if err != nil { 23 | fmt.Println(err) 24 | } 25 | fmt.Println(result) 26 | access_token := result["access_token"] 27 | fmt.Println(reflect.TypeOf(access_token), access_token) 28 | expires_in := result["expires_in"] 29 | fmt.Println(reflect.TypeOf(expires_in), expires_in) 30 | } 31 | -------------------------------------------------------------------------------- /users.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-06 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | /////////////////////////////////////////////// 读取接口 ///////////////////////////////////////////////// 9 | 10 | //获取用户信息 11 | func (api *APIClient) GET_users_show(params map[string]interface{}, result *User) error { 12 | return api.GET("users/show", params, result) 13 | } 14 | 15 | //通过个性域名获取用户信息 16 | func (api *APIClient) GET_users_domain_show(params map[string]interface{}, result *User) error { 17 | return api.GET("users/domain_show", params, result) 18 | } 19 | 20 | //批量获取用户的粉丝数、关注数、微博数 21 | func (api *APIClient) GET_users_counts(params map[string]interface{}, result *[]UserCounts) error { 22 | return api.GET("users/counts", params, result) 23 | } 24 | 25 | //废弃? 26 | /* 27 | func (api *APIClient) GET_users_show_rank(params map[string]interface{}, result *UserRank) error { 28 | return api.GET("users/show_rank", params, result) 29 | } 30 | */ 31 | -------------------------------------------------------------------------------- /common.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-08 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //通过地址编码获取地址名称 9 | func (api *APIClient) GET_common_code_to_location(params map[string]interface{}, result interface{}) error { 10 | return api.GET("common/code_to_location", params, result) 11 | } 12 | 13 | //获取城市列表 14 | func (api *APIClient) GET_common_get_city(params map[string]interface{}, result interface{}) error { 15 | return api.GET("common/get_city", params, result) 16 | } 17 | 18 | //获取省份列表 19 | func (api *APIClient) GET_common_get_province(params map[string]interface{}, result interface{}) error { 20 | return api.GET("common/get_province", params, result) 21 | } 22 | 23 | //获取国家列表 24 | func (api *APIClient) GET_common_get_country(params map[string]interface{}, result interface{}) error { 25 | return api.GET("common/get_country", params, result) 26 | } 27 | 28 | //获取时区配置表 29 | func (api *APIClient) GET_common_get_timezone(params map[string]interface{}, result interface{}) error { 30 | return api.GET("common/get_timezone", params, result) 31 | } 32 | -------------------------------------------------------------------------------- /account.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-08 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //获取隐私设置信息 9 | func (api *APIClient) GET_account_privacy(params map[string]interface{}, result *Config) error { 10 | return api.GET("account/get_privacy", params, result) 11 | } 12 | 13 | //获取所有学校列表 14 | func (api *APIClient) GET_account_profile_school_list(params map[string]interface{}, result *[]School) error { 15 | return api.GET("account/profile/school_list", params, result) 16 | } 17 | 18 | //获取当前用户API访问频率限制 19 | func (api *APIClient) GET_account_rate_limit_status(params map[string]interface{}, result *LimitStatus) error { 20 | return api.GET("account/rate_limit_status", params, result) 21 | } 22 | 23 | //获取用户的联系邮箱 **高级** 24 | func (api *APIClient) GET_account_get_uid(params map[string]interface{}, uid *UserID) error { 25 | return api.GET("account/get_uid", params, uid) 26 | } 27 | 28 | //OAuth授权之后获取用户UID 29 | func (api *APIClient) GET_account_get_email(params map[string]interface{}, email *Email) error { 30 | return api.GET("account/profile/email", params, email) 31 | } 32 | -------------------------------------------------------------------------------- /search.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //搜用户搜索建议 9 | func (api *APIClient) GET_search_suggestions_users(params map[string]interface{}, result interface{}) error { 10 | return api.GET("search/suggestions/users", params, result) 11 | } 12 | 13 | //搜学校搜索建议 14 | func (api *APIClient) GET_search_suggestions_schools(params map[string]interface{}, result interface{}) error { 15 | return api.GET("search/suggestions/schools", params, result) 16 | } 17 | 18 | //搜应用搜索建议 19 | func (api *APIClient) GET_search_suggestions_apps(params map[string]interface{}, result interface{}) error { 20 | return api.GET("search/suggestions/apps", params, result) 21 | } 22 | 23 | //联想搜索 24 | func (api *APIClient) GET_search_suggestions_at_users(params map[string]interface{}, result interface{}) error { 25 | return api.GET("search/suggestions/at_users", params, result) 26 | } 27 | 28 | //搜索某一话题下的微博 29 | func (api *APIClient) GET_search_topics(params map[string]interface{}, result *Topic) error { 30 | return api.GET("search/topics", params, result) 31 | } 32 | -------------------------------------------------------------------------------- /tags.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-06 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //返回指定用户的标签列表 9 | func (api *APIClient) GET_tags(params map[string]interface{}, result interface{}) error { 10 | return api.GET("tags", params, result) 11 | } 12 | 13 | //批量获取用户标签 14 | func (api *APIClient) GET_tags_tags_batch(params map[string]interface{}, result *[]Tags) error { 15 | return api.GET("tags/tags_batch", params, result) 16 | } 17 | 18 | //返回系统推荐的标签列表 19 | func (api *APIClient) GET_tags_suggestions(params map[string]interface{}, result interface{}) error { 20 | return api.GET("tags/suggestions", params, result) 21 | } 22 | 23 | //写入接口 24 | 25 | //添加用户标签 26 | func (api *APIClient) POST_tags_create(params map[string]interface{}, result interface{}) error { 27 | return api.POST("tags/create", params, result) 28 | } 29 | 30 | //删除用户标签 31 | func (api *APIClient) POST_tags_destroy(params map[string]interface{}, result interface{}) error { 32 | return api.POST("tags/destroy", params, result) 33 | } 34 | 35 | //批量删除用户标签 36 | func (api *APIClient) POST_tags_destroy_batch(params map[string]interface{}, result interface{}) error { 37 | return api.POST("tags/destroy_batch", params, result) 38 | } 39 | -------------------------------------------------------------------------------- /short_url.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //长链转短链 9 | func (api *APIClient) short_url_shorten(params map[string]interface{}, result interface{}) error { 10 | return api.GET("short_url/shorten", params, result) 11 | } 12 | 13 | //短链转长链 14 | func (api *APIClient) GET_short_url_expand(params map[string]interface{}, result interface{}) error { 15 | return api.GET("short_url/expand", params, result) 16 | } 17 | 18 | //获取短链接在微博上的微博分享数 19 | func (api *APIClient) GET_short_url_share_counts(params map[string]interface{}, result interface{}) error { 20 | return api.GET("short_url/share/counts", params, result) 21 | } 22 | 23 | //获取包含指定单个短链接的最新微博内容 24 | func (api *APIClient) GET_short_url_share_statuses(params map[string]interface{}, result interface{}) error { 25 | return api.GET("short_url/share/statuses", params, result) 26 | } 27 | 28 | //获取短链接在微博上的微博评论数 29 | func (api *APIClient) GET_short_url_comment_counts(params map[string]interface{}, result interface{}) error { 30 | return api.GET("short_url/comment/counts", params, result) 31 | } 32 | 33 | //获取包含指定单个短链接的最新微博评论 34 | func (api *APIClient) GET_short_url_comment_comments(params map[string]interface{}, result interface{}) error { 35 | return api.GET("short_url/comment/comments", params, result) 36 | } 37 | -------------------------------------------------------------------------------- /friendships_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | import ( 9 | // "fmt" 10 | "testing" 11 | ) 12 | 13 | func Test_GET_friendships_friends(t *testing.T) { 14 | t.SkipNow() 15 | kws := map[string]interface{}{ 16 | "uid": "2684726573", 17 | } 18 | result := new(Friendships) 19 | err := api.GET_friendships_friends(kws, result) 20 | debugCheckError(err) 21 | debugPrintln(len(*result.Users)) 22 | } 23 | 24 | func Test_GET_friendships_friends_in_common(t *testing.T) { 25 | t.SkipNow() 26 | kws := map[string]interface{}{ 27 | "uid": "1580095602", 28 | "suid": "2684726573", 29 | } 30 | result := new(Friendships) 31 | err := api.GET_friendships_friends_in_common(kws, result) 32 | debugCheckError(err) 33 | debugPrintln(len(*result.Users)) 34 | } 35 | 36 | func Test_GET_friendships_friends_ids(t *testing.T) { 37 | t.SkipNow() 38 | kws := map[string]interface{}{ 39 | "uid": "1580095602", 40 | } 41 | result := new(FriendsIDS) 42 | err := api.GET_friendships_friends_ids(kws, result) 43 | debugCheckError(err) 44 | debugPrintln(len(*result.Ids)) 45 | // fmt.Println(*result.Ids) 46 | } 47 | 48 | func Test_GET_friendships_followers_active(t *testing.T) { 49 | t.SkipNow() 50 | kws := map[string]interface{}{ 51 | "uid": "1580095602", 52 | } 53 | result := new([]User) 54 | err := api.GET_friendships_followers_active(kws, result) 55 | debugCheckError(err) 56 | debugPrintln(len(*result)) 57 | // fmt.Println(*result.Ids) 58 | } 59 | -------------------------------------------------------------------------------- /suggestions.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-15 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //获取系统推荐用户 9 | func (api *APIClient) GET_suggestions_users_hot(params map[string]interface{}, result *[]User) error { 10 | return api.GET("suggestions/users/hot", params, result) 11 | } 12 | 13 | //获取用户可能感兴趣的人 14 | func (api *APIClient) GET_suggestions_users_may_interested(params map[string]interface{}, result interface{}) error { 15 | return api.GET("suggestions/users/may_interested", params, result) 16 | } 17 | 18 | //获取系统推荐用户 19 | func (api *APIClient) GET_suggestions_users_by_status(params map[string]interface{}, result *SuggestionsUser) error { 20 | return api.GET("suggestions/users/by_status", params, result) 21 | } 22 | 23 | //主Feed微博按兴趣推荐排序 24 | func (api *APIClient) GET_suggestions_statuses_reorder(params map[string]interface{}, result *Topic) error { 25 | return api.GET("suggestions/statuses/reorder", params, result) 26 | } 27 | 28 | //主Feed微博按兴趣推荐排序的微博ID 29 | func (api *APIClient) GET_suggestions_statuses_reorder_ids(params map[string]interface{}, result interface{}) error { 30 | return api.GET("suggestions/statuses/reorder/ids", params, result) 31 | } 32 | 33 | //热门收藏 34 | func (api *APIClient) GET_suggestions_favorites_hot(params map[string]interface{}, result *[]Status) error { 35 | return api.GET("suggestions/favorites/hot", params, result) 36 | } 37 | 38 | //写入接口 39 | 40 | //不感兴趣的人 41 | func (api *APIClient) POST_suggestions_users_not_interested(params map[string]interface{}, result *User) error { 42 | return api.POST("suggestions/users/not_interested", params, result) 43 | } 44 | -------------------------------------------------------------------------------- /account_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_GET_account_privacy(t *testing.T) { 8 | t.SkipNow() 9 | kws := map[string]interface{}{ 10 | "access_token": api.access_token, 11 | "source": api.app_key, 12 | } 13 | result := new(Config) 14 | err := api.GET_account_privacy(kws, result) 15 | debugCheckError(err) 16 | debugPrintln((*result)) 17 | } 18 | 19 | func Test_GET_account_rate_limit_status(t *testing.T) { 20 | t.SkipNow() 21 | kws := map[string]interface{}{ 22 | "access_token": api.access_token, 23 | "source": api.app_key, 24 | } 25 | result := new(LimitStatus) 26 | err := api.GET_account_rate_limit_status(kws, result) 27 | debugCheckError(err) 28 | debugPrintln((*result)) 29 | } 30 | 31 | func Test_GET_account_get_uid(t *testing.T) { 32 | t.SkipNow() 33 | kws := map[string]interface{}{ 34 | "access_token": api.access_token, 35 | "source": api.app_key, 36 | } 37 | result := new(UserID) 38 | err := api.GET_account_get_uid(kws, result) 39 | debugCheckError(err) 40 | debugPrintln((*result)) 41 | } 42 | 43 | func Test_GET_account_profile_school_list(t *testing.T) { 44 | t.SkipNow() 45 | kws := map[string]interface{}{ 46 | "access_token": api.access_token, 47 | "source": api.app_key, 48 | "keyword": "科大", 49 | } 50 | result := new([]School) 51 | err := api.GET_account_profile_school_list(kws, result) 52 | debugCheckError(err) 53 | debugPrintln((*result)) 54 | } 55 | 56 | func Test_GET_account_get_email(t *testing.T) { 57 | t.SkipNow() 58 | kws := map[string]interface{}{ 59 | "access_token": api.access_token, 60 | "source": api.app_key, 61 | } 62 | result := new(Email) 63 | err := api.GET_account_get_email(kws, result) 64 | debugCheckError(err) 65 | debugPrintln((*result)) 66 | } 67 | -------------------------------------------------------------------------------- /comments.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-06 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | /////////////////////////////////////////////// 读取接口 ///////////////////////////////////////////////// 9 | 10 | //获取某条微博的评论列表 11 | func (api *APIClient) GET_comments_show(params map[string]interface{}, result *Comments) error { 12 | return api.GET("comments/show", params, result) 13 | } 14 | 15 | //我发出的评论列表 16 | func (api *APIClient) GET_comments_by_me(params map[string]interface{}, result *Comments) error { 17 | return api.GET("comments/by_me", params, result) 18 | } 19 | 20 | //我收到的评论列表 21 | func (api *APIClient) GET_comments_to_me(params map[string]interface{}, result *Comments) error { 22 | return api.GET("comments/to_me", params, result) 23 | } 24 | 25 | //获取用户发送及收到的评论列表 26 | func (api *APIClient) GET_comments_timeline(params map[string]interface{}, result *Comments) error { 27 | return api.GET("comments/timeline", params, result) 28 | } 29 | 30 | //获取@到我的评论 31 | func (api *APIClient) GET_comments_mentions(params map[string]interface{}, result *Comments) error { 32 | return api.GET("comments/mentions", params, result) 33 | } 34 | 35 | //批量获取评论内容 36 | func (api *APIClient) GET_comments_show_batch(params map[string]interface{}, result *Comments) error { 37 | return api.GET("comments/show_batch", params, result) 38 | } 39 | 40 | /////////////////////////////////////////////// 写入接口 ///////////////////////////////////////////////// 41 | 42 | //评论一条微博 43 | func (api *APIClient) POST_comments_create(params map[string]interface{}, result *Comment) error { 44 | return api.POST("comments/create", params, result) 45 | } 46 | 47 | //删除一条评论 48 | func (api *APIClient) POST_comments_destroy(params map[string]interface{}, result *Comment) error { 49 | return api.POST("comments/destroy", params, result) 50 | } 51 | 52 | //批量删除评论 53 | func (api *APIClient) POST_comments_destroy_batch(params map[string]interface{}, result *[]Comment) error { 54 | return api.POST("comments/destroy_batch", params, result) 55 | } 56 | 57 | //回复一条评论 58 | func (api *APIClient) POST_comments_reply(params map[string]interface{}, result *Comment) error { 59 | return api.POST("comments/reply", params, result) 60 | } 61 | -------------------------------------------------------------------------------- /statuses_test.go: -------------------------------------------------------------------------------- 1 | package weigo 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | var api *APIClient 9 | 10 | type Times struct { 11 | time.Time 12 | } 13 | 14 | func init() { 15 | if api == nil { 16 | api = NewAPIClient("3231340587", "702b4bcc6d56961f569943ecee1a76f4", "https://api.weibo.com/oauth2/default.html", "token") 17 | api.SetAccessToken("2.00VBqgvCZS4gWDb3940dd56eFfitSB", 1542004259) 18 | } 19 | } 20 | 21 | func Test_GET_statuses_user_timeline(t *testing.T) { 22 | t.SkipNow() 23 | kws := map[string]interface{}{ 24 | "mid": "yybyOssa9", 25 | "type": 1, 26 | "isBase62": 1, 27 | } 28 | var result string 29 | err := api.GET_statuses_queryid(kws, &result) 30 | debugCheckError(err) 31 | debugPrintln(result) 32 | // fmt.Println(result) 33 | } 34 | 35 | func Test_GET_statuses_home_timeline(t *testing.T) { 36 | t.SkipNow() 37 | kws := map[string]interface{}{ 38 | "uid": "2684726573", 39 | } 40 | result := new(Statuses) 41 | err := api.GET_statuses_home_timeline(kws, result) 42 | debugCheckError(err) 43 | // debugPrintln(len(*result.Statuses)) 44 | // fmt.Println(result.Statuses) 45 | } 46 | 47 | func Test_GET_statuses_repost_timeline(t *testing.T) { 48 | t.SkipNow() 49 | kws := map[string]interface{}{ 50 | "id": "3551749023600582", 51 | } 52 | result := new(Reposts) 53 | err := api.GET_statuses_repost_timeline(kws, result) 54 | debugCheckError(err) 55 | debugPrintln(len(*result.Reposts)) 56 | } 57 | 58 | func Test_POST_statuses_repost(t *testing.T) { 59 | t.SkipNow() 60 | kws := map[string]interface{}{ 61 | "id": "3551749023600582", 62 | } 63 | result := new(Status) 64 | err := api.POST_statuses_repost(kws, result) 65 | debugCheckError(err) 66 | debugPrintln(*result) 67 | } 68 | 69 | func Test_POST_statuses_update(t *testing.T) { 70 | t.SkipNow() 71 | kws := map[string]interface{}{ 72 | "status": "Testing...Testing...", 73 | } 74 | result := new(Status) 75 | err := api.POST_statuses_update(kws, result) 76 | debugCheckError(err) 77 | debugPrintln(*result) 78 | } 79 | 80 | func Test_POST_statuses_destory(t *testing.T) { 81 | t.SkipNow() 82 | kws := map[string]interface{}{ 83 | "id": "3592749137795387", 84 | } 85 | result := new(Status) 86 | err := api.POST_statuses_destroy(kws, result) 87 | debugCheckError(err) 88 | debugPrintln(*result) 89 | } 90 | -------------------------------------------------------------------------------- /favorites.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: vuiletgo(china.violetgo@gmail.com) 3 | * Date: 13-12-11 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | //读取接口 9 | 10 | //获取当前用户的收藏列表 11 | func (api *APIClient) GET_favorites(params map[string]interface{}, result *Favorites) error { 12 | return api.GET("favorites", params, result) 13 | } 14 | 15 | //获取当前用户的收藏列表的ID 16 | func (api *APIClient) GET_favorites_ids(params map[string]interface{}, result *FavoritesID) error { 17 | return api.GET("favorites/ids", params, result) 18 | } 19 | 20 | //获取单条收藏信息 21 | func (api *APIClient) GET_favorites_show(params map[string]interface{}, result *Favorites) error { 22 | return api.GET("favorites/show", params, result) 23 | } 24 | 25 | //获取当前用户某个标签下的收藏列表 26 | func (api *APIClient) GET_favorites_by_tags(params map[string]interface{}, result *Favorites) error { 27 | return api.GET("favorites/by_tags", params, result) 28 | } 29 | 30 | //当前登录用户的收藏标签列表 31 | func (api *APIClient) GET_favorites_tags(params map[string]interface{}, result interface{}) error { 32 | return api.GET("favorites/tags", params, result) 33 | } 34 | 35 | //获取当前用户某个标签下的收藏列表的ID 36 | func (api *APIClient) GET_favorites_by_tags_ids(params map[string]interface{}, result *FavoritesID) error { 37 | return api.GET("favorites/by_tags/ids", params, result) 38 | } 39 | 40 | //写入接口 41 | 42 | //添加收藏 43 | func (api *APIClient) POST_favorites_create(params map[string]interface{}, result *Favorites) error { 44 | return api.POST("favorites/create", params, result) 45 | } 46 | 47 | //删除收藏 48 | func (api *APIClient) POST_favorites_destroy(params map[string]interface{}, result *Favorites) error { 49 | return api.POST("favorites/destroy", params, result) 50 | } 51 | 52 | //批量删除收藏 53 | func (api *APIClient) POST_favorites_destroy_batch(params map[string]interface{}, result interface{}) error { 54 | return api.POST("favorites/destroy_batch", params, result) 55 | } 56 | 57 | //更新收藏标签 58 | func (api *APIClient) POST_favorites_tags_update(params map[string]interface{}, result *Favorites) error { 59 | return api.POST("favorites/tags/update", params, result) 60 | } 61 | 62 | //更新当前用户所有收藏下的指定标签 63 | func (api *APIClient) POST_favorites_tags_update_batch(params map[string]interface{}, result interface{}) error { 64 | return api.POST("favorites/tags/update_batch ", params, result) 65 | } 66 | 67 | //删除当前用户所有收藏下的指定标签 68 | func (api *APIClient) POST_favorites_tags_destroy_batch(params map[string]interface{}, result interface{}) error { 69 | return api.POST("favorites/tags/destroy_batch", params, result) 70 | } 71 | -------------------------------------------------------------------------------- /friendships.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-06 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | /////////////////////////////////////////////// 读取接口 ///////////////////////////////////////////////// 9 | 10 | //获取用户信息 11 | func (api *APIClient) GET_friendships_friends(params map[string]interface{}, result *Friendships) error { 12 | return api.GET("friendships/friends", params, result) 13 | } 14 | 15 | //批量获取当前登录用户的关注人的备注信息 ** 高级接口 ** 16 | func (api *APIClient) GET_friendships_friends_remark_batch(params map[string]interface{}, result interface{}) error { 17 | return api.GET("friendships/friends/remark_batch", params, result) 18 | } 19 | 20 | //获取共同关注人列表 21 | func (api *APIClient) GET_friendships_friends_in_common(params map[string]interface{}, result *Friendships) error { 22 | return api.GET("friendships/friends/in_common", params, result) 23 | } 24 | 25 | //获取双向关注列表 26 | func (api *APIClient) GET_friendships_friends_bilateral(params map[string]interface{}, result *Friendships) error { 27 | return api.GET("friendships/friends/bilateral", params, result) 28 | } 29 | 30 | //获取双向关注UID列表 31 | func (api *APIClient) GET_friendships_friends_bilateral_ids(params map[string]interface{}, result *FriendsIDS) error { 32 | return api.GET("friendships/friends/bilateral/ids", params, result) 33 | } 34 | 35 | //获取用户关注对象UID列表 36 | func (api *APIClient) GET_friendships_friends_ids(params map[string]interface{}, result *FriendsIDS) error { 37 | return api.GET("friendships/friends/ids", params, result) 38 | } 39 | 40 | //获取用户粉丝列表 41 | func (api *APIClient) GET_friendships_followers(params map[string]interface{}, result *Friendships) error { 42 | return api.GET("friendships/followers", params, result) 43 | } 44 | 45 | //获取用户粉丝UID列表 46 | func (api *APIClient) GET_friendships_followers_ids(params map[string]interface{}, result *FriendsIDS) error { 47 | return api.GET("friendships/followers/ids", params, result) 48 | } 49 | 50 | //获取用户优质粉丝列表 51 | func (api *APIClient) GET_friendships_followers_active(params map[string]interface{}, result *[]User) error { 52 | return api.GET("friendships/followers/active", params, result) 53 | } 54 | 55 | //获取我的关注人中关注了指定用户的人 56 | func (api *APIClient) GET_friendships_friends_chain_followers(params map[string]interface{}, result *Friendships) error { 57 | return api.GET("friendships/friends_chain/followers", params, result) 58 | } 59 | 60 | //TODO result type 61 | //获取两个用户关系的详细情况 62 | func (api *APIClient) GET_friendships_show(params map[string]interface{}, result interface{}) error { 63 | return api.GET("friendships/show", params, result) 64 | } 65 | 66 | /////////////////////////////////////////////// 写入接口 ///////////////////////////////////////////////// 67 | 68 | //关注某用户 69 | func (api *APIClient) POST_friendships_create(params map[string]interface{}, result *User) error { 70 | return api.POST("friendships/create", params, result) 71 | } 72 | 73 | //取消关注某用户 74 | func (api *APIClient) POST_friendships_destroy(params map[string]interface{}, result *User) error { 75 | return api.POST("friendships/destroy", params, result) 76 | } 77 | 78 | //移除当前登录用户的粉丝 ** 高级接口 ** 79 | func (api *APIClient) POST_friendships_followers_destroy(params map[string]interface{}, result *User) error { 80 | return api.POST("friendships/followers/destroy", params, result) 81 | } 82 | 83 | //更新关注人备注 ** 高级接口 ** 84 | func (api *APIClient) POST_friendships_remark_update(params map[string]interface{}, result *User) error { 85 | return api.POST("friendships/remark/update", params, result) 86 | } 87 | -------------------------------------------------------------------------------- /pool.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao 3 | * Email: xiocode@gmail.com 4 | * Github: github.com/xiocode 5 | * File: pool.go 6 | * Description: generic pool 7 | */ 8 | 9 | package weigo 10 | 11 | import ( 12 | "errors" 13 | "fmt" 14 | "sync" 15 | ) 16 | 17 | // Factory is a function to create new connections. 18 | type Factory func() (interface{}, error) 19 | 20 | // Pool allows you to use a pool of net.Conn connections. 21 | type Pool struct { 22 | mu sync.Mutex 23 | elements chan interface{} // storage for interface{} 24 | factory Factory // net.Conn generator 25 | } 26 | 27 | // New returns a new pool with an initial capacity and maximum capacity. 28 | // Factory is used when initial capacity is greater than zero to fill the 29 | // pool. 30 | func NewConnPool(size, capacity int, factory Factory) (*Pool, error) { 31 | if size <= 0 || capacity <= 0 || size > capacity { 32 | return nil, errors.New("invalid capacity settings") 33 | } 34 | 35 | pool := &Pool{ 36 | elements: make(chan interface{}, capacity), 37 | factory: factory, 38 | } 39 | 40 | // create initial connections, if something goes wrong, 41 | // just close the pool error out. 42 | for i := 0; i < size; i++ { 43 | element, err := factory() 44 | if err != nil { 45 | return nil, fmt.Errorf("factory is not able to fill the pool: %s", err) 46 | } 47 | pool.elements <- element 48 | } 49 | 50 | return pool, nil 51 | } 52 | 53 | func (p *Pool) getElements() chan interface{} { 54 | p.mu.Lock() 55 | elements := p.elements 56 | p.mu.Unlock() 57 | return elements 58 | } 59 | 60 | // Get returns a new connection from the pool. After using the connection it 61 | // should be put back via the Put() method. If there is no new connection 62 | // available in the pool, a new connection will be created via the Factory() 63 | // method. 64 | func (p *Pool) Get() (interface{}, error) { 65 | elements := p.getElements() 66 | if elements == nil { 67 | return nil, errors.New("pool is closed") 68 | } 69 | 70 | select { 71 | case element := <-elements: 72 | if element == nil { 73 | return nil, errors.New("pool is closed") 74 | } 75 | return element, nil 76 | default: 77 | return p.factory() 78 | } 79 | } 80 | 81 | // Put puts an existing connection into the pool. If the pool is full or 82 | // closed, conn is simply closed. A nil conn will be rejected. Putting into a 83 | // destroyed or full pool will be counted as an error. 84 | func (p *Pool) Put(element interface{}) error { 85 | if element == nil { 86 | return errors.New("connection is nil. rejecting") 87 | } 88 | 89 | p.mu.Lock() 90 | defer p.mu.Unlock() 91 | 92 | if p.elements == nil { 93 | return errors.New("pool is closed") 94 | } 95 | 96 | select { 97 | case p.elements <- element: 98 | return nil 99 | default: 100 | return errors.New("pool is full") 101 | } 102 | } 103 | 104 | // Close closes the pool and all its connections. After Close() the 105 | // pool is no longer usable. 106 | func (p *Pool) Close() { 107 | p.mu.Lock() 108 | elements := p.elements 109 | p.elements = nil 110 | p.factory = nil 111 | p.mu.Unlock() 112 | 113 | if elements == nil { 114 | return 115 | } 116 | 117 | close(elements) 118 | for _ = range elements { 119 | } 120 | } 121 | 122 | // MaximumCapacity returns the maximum capacity of the pool 123 | func (p *Pool) MaximumCapacity() int { return cap(p.getElements()) } 124 | 125 | // CurrentCapacity returns the current capacity of the pool. 126 | func (p *Pool) CurrentCapacity() int { return len(p.getElements()) } 127 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Go Weibo SDK 2 | ======== 3 | Sina Weibo SDK For Gopher 4 | 5 | [](https://drone.io/github.com/going/weigo/latest) 6 | 7 | 文档请看测试用例,哈哈! 8 | 9 | WIP 部分高级功能啥的还没有添加静态方法。。常用的都已经添加了。。有需求请提啊! 10 | 11 | ##Install: 12 | ```go 13 | go get -u github.com/xiocode/weigo 14 | ``` 15 | 16 | ##Usage: 17 | http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2 18 | 参照官方文档调用对应的方法.目前weigo支持的功能可以参考本项目的[wiki](https://github.com/violetgo/weigo/wiki). 19 | ```go 20 | package weigo 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | var api *APIClient 27 | 28 | func init() { 29 | if api == nil { 30 | api = NewAPIClient("3231340587", "702b4bcc6d56961f569943ecee1a76f4", "http://2.xweiboproxy.sinaapp.com/callback.php", "code") 31 | api.SetAccessToken("2.00VBqgvCZS4gWDb3940dd56eFfitSB", 1519925461) 32 | } 33 | } 34 | 35 | // 先获取 GetAuthorizeUrl 打开浏览器操作之后 得到 http://127.0.0.1/callback?code=198ea555a7efbbfd90caa92c86feb2b5 36 | // code的值是RequestAccessToken的参数 37 | func TestGetAuthorizeUrl(t *testing.T) { 38 | api := NewAPIClient("3417104247", "f318153f6a80329f06c1d20842ee6e91", "http://127.0.0.1/callback", "code") 39 | authorize_url, err := api.GetAuthorizeUrl(nil) 40 | if err != nil { 41 | fmt.Println(err) 42 | } 43 | fmt.Println(authorize_url) 44 | } 45 | 46 | func TestRequestAccessToken(t *testing.T) { 47 | api := NewAPIClient("3417104247", "f318153f6a80329f06c1d20842ee6e91", "http://127.0.0.1/callback", "code") 48 | var result map[string]interface{} 49 | err := api.RequestAccessToken("1fdaa295b73d2a9568e284383ced5e9e", &result) // code 50 | if err != nil { 51 | fmt.Println(err) 52 | } 53 | fmt.Println(result) 54 | access_token := result["access_token"] 55 | fmt.Println(reflect.TypeOf(access_token), access_token) 56 | expires_in := result["expires_in"] 57 | fmt.Println(reflect.TypeOf(expires_in), expires_in) 58 | } 59 | 60 | func Test_GET_statuses_user_timeline(t *testing.T) { 61 | kws := map[string]interface{}{ 62 | "uid": "2684726573", 63 | } 64 | result := new(Statuses) 65 | err := api.GET_statuses_user_timeline(kws, result) 66 | debugCheckError(err) 67 | debugPrintln(len(*result.Statuses)) 68 | } 69 | 70 | func Test_GET_statuses_home_timeline(t *testing.T) { 71 | kws := map[string]interface{}{ 72 | "uid": "2684726573", 73 | } 74 | result := new(Statuses) 75 | err := api.GET_statuses_home_timeline(kws, result) 76 | debugCheckError(err) 77 | debugPrintln(len(*result.Statuses)) 78 | } 79 | 80 | func Test_GET_statuses_repost_timeline(t *testing.T) { 81 | kws := map[string]interface{}{ 82 | "id": "3551749023600582", 83 | } 84 | result := new(Reposts) 85 | err := api.GET_statuses_repost_timeline(kws, result) 86 | debugCheckError(err) 87 | debugPrintln(len(*result.Reposts)) 88 | } 89 | 90 | func Test_POST_statuses_repost(t *testing.T) { 91 | kws := map[string]interface{}{ 92 | "id": "3551749023600582", 93 | } 94 | result := new(Status) 95 | err := api.POST_statuses_repost(kws, result) 96 | debugCheckError(err) 97 | debugPrintln(*result) 98 | } 99 | 100 | func Test_POST_statuses_repost(t *testing.T) { 101 | kws := map[string]interface{}{ 102 | "status": "Testing...Testing...", 103 | } 104 | result := new(Status) 105 | err := api.POST_statuses_update(kws, result) 106 | debugCheckError(err) 107 | debugPrintln(*result) 108 | } 109 | 110 | func Test_POST_statuses_repost(t *testing.T) { 111 | kws := map[string]interface{}{ 112 | "id": "3556138715301190", 113 | } 114 | result := new(Status) 115 | err := api.POST_statuses_destroy(kws, result) 116 | debugCheckError(err) 117 | debugPrintln(*result) 118 | } 119 | 120 | ``` 121 | 122 | Weibo: http://weibo.com/xceman @XIOCODE 123 | Gmail: xiocode@gmail.com 124 | -------------------------------------------------------------------------------- /statuses.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-06 4 | * Version: 0.02 5 | */ 6 | package weigo 7 | 8 | import ( 9 | "github.com/going/toolkit/dig" 10 | ) 11 | 12 | /////////////////////////////////////////////// 读取接口 ///////////////////////////////////////////////// 13 | 14 | //获取用户发布的微博 15 | func (api *APIClient) GET_statuses_user_timeline(params map[string]interface{}, result *Statuses) error { 16 | return api.GET("statuses/user_timeline", params, result) 17 | } 18 | 19 | //获取最新的公共微博 20 | func (api *APIClient) GET_statuses_public_timeline(params map[string]interface{}, result *Statuses) error { 21 | return api.GET("statuses/public_timeline", params, result) 22 | } 23 | 24 | //获取当前登录用户及其所关注用户的最新微博 25 | func (api *APIClient) GET_statuses_friends_timeline(params map[string]interface{}, result *Statuses) error { 26 | return api.GET("statuses/friends_timeline", params, result) 27 | } 28 | 29 | //获取当前登录用户及其所关注用户的最新微博 30 | func (api *APIClient) GET_statuses_home_timeline(params map[string]interface{}, result *Statuses) error { 31 | return api.GET("statuses/home_timeline", params, result) 32 | } 33 | 34 | //返回一条原创微博的最新转发微博 35 | func (api *APIClient) GET_statuses_repost_timeline(params map[string]interface{}, result *Reposts) error { 36 | return api.GET("statuses/repost_timeline", params, result) 37 | } 38 | 39 | //批量获取指定的一批用户的微博列表 ** 高级接口 ** 40 | func (api *APIClient) GET_statuses_timeline_batch(params map[string]interface{}, result *Statuses) error { 41 | return api.GET("statuses/timeline_batch", params, result) 42 | } 43 | 44 | //获取用户发布的微博的ID 45 | func (api *APIClient) GET_statuses_user_timeline_ids(params map[string]interface{}, result *TimelineIDs) error { 46 | return api.GET("statuses//user_timeline/ids", params, result) 47 | } 48 | 49 | //获取一条原创微博的最新转发微博的ID 50 | func (api *APIClient) GET_statuses_repost_timeline_ids(params map[string]interface{}, result *TimelineIDs) error { 51 | return api.GET("statuses/repost_timeline/ids", params, result) 52 | } 53 | 54 | //获取当前登录用户及其所关注用户的最新微博的ID 55 | func (api *APIClient) GET_statuses_friends_timeline_ids(params map[string]interface{}, result *TimelineIDs) error { 56 | return api.GET("statuses/friends_timeline/ids", params, result) 57 | } 58 | 59 | //返回用户转发的最新微博 60 | func (api *APIClient) GET_statuses_repost_by_me(params map[string]interface{}, result *Statuses) error { 61 | return api.GET("statuses/repost_by_me", params, result) 62 | } 63 | 64 | //获取@当前用户的最新微博 65 | func (api *APIClient) GET_statuses_mentions(params map[string]interface{}, result *Statuses) error { 66 | return api.GET("statuses/mentions", params, result) 67 | } 68 | 69 | //获取@当前用户的最新微博的ID 70 | func (api *APIClient) GET_statuses_mentions_ids(params map[string]interface{}, result *TimelineIDs) error { 71 | return api.GET("statuses/mentions/ids", params, result) 72 | } 73 | 74 | //获取双向关注用户的最新微博 75 | func (api *APIClient) GET_statuses_bilateral_timeline(params map[string]interface{}, result *Statuses) error { 76 | return api.GET("statuses/bilateral_timeline", params, result) 77 | } 78 | 79 | //根据ID获取单条微博信息 80 | func (api *APIClient) GET_statuses_show(params map[string]interface{}, result *Status) error { 81 | return api.GET("statuses/show", params, result) 82 | } 83 | 84 | //根据微博ID批量获取微博信息 85 | func (api *APIClient) GET_statuses_show_batch(params map[string]interface{}, result *Statuses) error { 86 | return api.GET("statuses/show_batch", params, result) 87 | } 88 | 89 | //通过id获取mid 90 | func (api *APIClient) GET_statuses_querymid(params map[string]interface{}, mid *string) error { 91 | result := new(map[string]interface{}) 92 | err := api.GET("statuses/querymid", params, result) 93 | dig.Get(result, mid, "mid") 94 | return err 95 | } 96 | 97 | //通过mid获取id 98 | func (api *APIClient) GET_statuses_queryid(params map[string]interface{}, id *string) error { 99 | result := new(map[string]interface{}) 100 | err := api.GET("statuses/queryid", params, result) 101 | dig.Get(result, id, "id") 102 | return err 103 | } 104 | 105 | //批量获取指定微博的转发数评论数 106 | func (api *APIClient) GET_statuses_count(params map[string]interface{}, result *[]StatusCount) error { 107 | return api.GET("statuses/count", params, result) 108 | } 109 | 110 | //获取当前登录用户关注的人发给其的定向微博 ** 高级接口 ** 111 | func (api *APIClient) GET_statuses_to_me(params map[string]interface{}, result *Statuses) error { 112 | return api.GET("statuses/to_me", params, result) 113 | } 114 | 115 | //获取当前登录用户关注的人发给其的定向微博ID列表 ** 高级接口 ** 116 | func (api *APIClient) GET_statuses_to_me_ids(params map[string]interface{}, result *TimelineIDs) error { 117 | return api.GET("statuses/to_me/ids", params, result) 118 | } 119 | 120 | /////////////////////////////////////////////// 写入接口 ///////////////////////////////////////////////// 121 | 122 | //转发一条微博信息 123 | func (api *APIClient) POST_statuses_repost(params map[string]interface{}, result *Status) error { 124 | return api.POST("statuses/repost", params, result) 125 | } 126 | 127 | //删除微博信息 128 | func (api *APIClient) POST_statuses_destroy(params map[string]interface{}, result *Status) error { 129 | return api.POST("statuses/destroy", params, result) 130 | } 131 | 132 | //发布一条微博信息 133 | func (api *APIClient) POST_statuses_update(params map[string]interface{}, result *Status) error { 134 | return api.POST("statuses/update", params, result) 135 | } 136 | 137 | //上传图片并发布一条微博 138 | func (api *APIClient) POST_statuses_upload(params map[string]interface{}, result *Status) error { 139 | return api.UPLOAD("statuses/upload", params, result) 140 | } 141 | 142 | //发布一条微博同时指定上传的图片或图片url ** 高级接口 ** 143 | func (api *APIClient) POST_statuses_upload_url_text(params map[string]interface{}, result *Status) error { 144 | return api.POST("statuses/upload_url_text", params, result) 145 | } 146 | 147 | //屏蔽某条微博 ** 高级接口 ** 148 | func (api *APIClient) POST_statuses_filter_create(params map[string]interface{}, result *Status) error { 149 | return api.POST("statuses/filter/create", params, result) 150 | } 151 | 152 | //屏蔽某个@我的微博及后续由其转发引起的@提及 ** 高级接口 ** 153 | func (api *APIClient) POST_statuses_mentions_shield(params map[string]interface{}, result interface{}) error { 154 | return api.POST("statuses/mentions/shield", params, result) 155 | } 156 | -------------------------------------------------------------------------------- /fileds.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao(xiocode@gmail.com) 3 | * Date: 13-03-06 4 | * Version: 0.02 5 | * modify by violetgo 6 | */ 7 | package weigo 8 | 9 | type Status struct { 10 | Id int64 `json:"id"` 11 | Mid string `json:"mid"` 12 | Idstr string `json:"idstr"` 13 | Text string `json:"text"` 14 | Source string `json:"source"` 15 | Favorited bool `json:"favorited"` 16 | Truncated bool `json:"truncated"` 17 | In_reply_to_status_id string `json:"in_reply_to_status_id"` //暂未支持 18 | In_reply_to_user_id string `json:"in_reply_to_user_id"` //暂未支持 19 | In_reply_to_screen_name string `json:"in_reply_to_screen_name"` //暂未支持 20 | Thumbnail_pic string `json:"thumbnail_pic"` 21 | Bmiddle_pic string `json:"bmiddle_pic"` 22 | Original_pic string `json:"original_pic"` 23 | Geo interface{} `json:"geo"` //{"type": "Point","coordinates": [21.231153,110.418708]} 24 | User *User `json:"user,omitempty"` 25 | Retweeted_status *Status `json:"retweeted_status,omitempty"` 26 | Reposts_count int64 `json:"reposts_count"` 27 | Comments_count int64 `json:"comments_count"` 28 | Attitudes_count int64 `json:"attitudes_count"` 29 | Mlevel int64 `json:"mlevel"` //暂未支持 30 | Visible interface{} `json:"visible"` //{"type": 0,"list_id": 0} 31 | Created_at string `json:"created_at"` 32 | } 33 | 34 | type User struct { 35 | Id int64 `json:"id"` 36 | Idstr string `json:"idstr"` 37 | Screen_name string `json:"screen_name"` 38 | Name string `json:"name"` 39 | Province string `json:"province"` 40 | City string `json:"city"` 41 | Location string `json:"location"` 42 | Description string `json:"description"` 43 | Url string `json:"url"` 44 | Profile_image_url string `json:"profile_image_url"` 45 | Profile_url string `json:"profile_url"` 46 | Domain string `json:"domain"` 47 | Weihao string `json:"weihao"` 48 | Gender string `json:"gender"` 49 | Followers_count int64 `json:"followers_count"` 50 | Friends_count int64 `json:"friends_count"` 51 | Statuses_count int64 `json:"statuses_count"` 52 | Favourites_count int64 `json:"favourites_count"` 53 | Created_at string `json:"created_at"` 54 | Following bool `json:"following"` 55 | Allow_all_act_msg bool `json:"allow_all_act_msg"` 56 | Geo_enabled bool `json:"geo_enabled"` 57 | Verified bool `json:"verified"` 58 | Verified_type int64 `json:"verified_type"` 59 | Remark string `json:"remark"` 60 | Status *Status `json:"status,omitempty"` 61 | Allow_all_comment bool `json:"allow_all_comment"` 62 | Avatar_large string `json:"avatar_large"` 63 | Verified_reason string `json:"verified_reason"` 64 | Follow_me bool `json:"follow_me"` 65 | Online_status int64 `json:"online_status"` 66 | Bi_followers_count int64 `json:"bi_followers_count"` 67 | Lang string `json:"lang"` 68 | Star int64 `json:"star"` 69 | Mbtype int64 `json:"mbtype"` 70 | Mbrank int64 `json:"mbrank"` 71 | Block_word int64 `json:"block_word"` 72 | } 73 | 74 | //UserTimeline, HomeTimeline... 75 | type Statuses struct { 76 | Statuses *[]Status `json:"statuses"` 77 | Hasvisible bool `json:"hasvisible"` 78 | Previous_cursor int64 `json:"previous_cursor"` 79 | Next_cursor int64 `json:"next_cursor"` 80 | Total_number int64 `json:"total_number"` 81 | Marks []interface{} `json:"marks,omitempty"` 82 | } 83 | 84 | type Reposts struct { 85 | Reposts *[]Status `json:"reposts"` 86 | Hasvisible bool `json:"hasvisible"` 87 | Previous_cursor int64 `json:"previous_cursor"` 88 | Next_cursor int64 `json:"next_cursor"` 89 | Total_number int64 `json:"total_number"` 90 | Marks []interface{} `json:"marks,omitempty"` 91 | } 92 | 93 | type Comments struct { 94 | Comments *[]Comment `json:"comments,omitempty"` 95 | Hasvisible bool `json:"hasvisible"` 96 | Previous_cursor int64 `json:"previous_cursor"` 97 | Next_cursor int64 `json:"next_cursor"` 98 | Total_number int64 `json:"total_number"` 99 | Marks []interface{} `json:"marks,omitempty"` 100 | } 101 | 102 | type UserCounts struct { 103 | Id int64 `json:"id"` 104 | Followers_count int64 `json:"followers_count"` 105 | Friends_count int64 `json:"friends_count"` 106 | Statuses_count int64 `json:"statuses_count"` 107 | Private_friends_count int64 `json:"private_friends_count,omitempty"` 108 | } 109 | 110 | type Comment struct { 111 | Created_at string `json:"created_at"` 112 | Id int64 `json:"id"` 113 | Text string `json:"text"` 114 | Source string `json:"source"` 115 | User *User `json:"user,omitempty"` 116 | Mid string `json:"mid"` 117 | Idstr string `json:"idstr"` 118 | Status *Status `json:"status,omitempty"` 119 | Reply_comment *Comment `json:"reply_comment,omitempty"` 120 | } 121 | 122 | type UserRank struct { 123 | Uid int64 `json:"uid"` 124 | Rank int64 `json:"rank"` 125 | } 126 | 127 | //friends_timeline_ids, repost_timeline_ids 128 | type TimelineIDs struct { 129 | Statuses []string `json:"statuses"` 130 | Hasvisible bool `json:"hasvisible"` 131 | Previous_cursor int64 `json:"previous_cursor"` 132 | Next_cursor int64 `json:"next_cursor"` 133 | Total_number int64 `json:"total_number"` 134 | Marks []interface{} `json:"marks,omitempty"` 135 | } 136 | 137 | type StatusCount struct { 138 | Id int64 `json:"id"` 139 | Comments int64 `json:"comments"` 140 | Reposts int64 `json:"reposts"` 141 | Attitudes int64 `json:"attitudes,omitempty"` 142 | } 143 | 144 | type Friendships struct { 145 | Users *[]User `json:"users"` 146 | Previous_cursor int64 `json:"previous_cursor,omitempty"` 147 | Next_cursor int64 `json:"next_cursor,omitempty"` 148 | Total_number int64 `json:"total_number,omitempty"` 149 | } 150 | 151 | type FriendsIDS struct { 152 | Ids *[]int64 `json:"ids"` 153 | Previous_cursor int64 `json:"previous_cursor,omitempty"` 154 | Next_cursor int64 `json:"next_cursor,omitempty"` 155 | Total_number int64 `json:"total_number,omitempty"` 156 | } 157 | 158 | type Config struct { 159 | Comment int64 `json:"comment"` 160 | Geo int64 `json:"geo"` 161 | Message int64 `json:"message"` 162 | Realname int64 `json:"realname"` 163 | Badge int64 `json:"badge"` 164 | Mobile int64 `json:"mobile"` 165 | Webim int64 `json:"webim"` 166 | } 167 | 168 | type LimitStatus struct { 169 | Ip_limit int64 `json:"ip_limit"` 170 | Limit_time_unit string `json:"limit_time_unit"` 171 | Remaining_ip_hits int64 `json:"remaining_ip_hits"` 172 | Remaining_user_hits int64 `json:"remaining_user_hits"` 173 | Reset_time string `json:"reset_time"` 174 | Reset_time_in_seconds int64 `json:"reset_time_in_seconds"` 175 | User_limit int64 `json:"user_limit"` 176 | } 177 | 178 | type UserID struct { 179 | Uid int64 `json:"uid"` 180 | } 181 | 182 | type Email struct { 183 | Email string `json:"email"` 184 | } 185 | 186 | type School struct { 187 | Id int64 `json:"id"` 188 | Name string `json:"name"` 189 | } 190 | 191 | type Tags struct { 192 | Tags []map[string]interface{} `json:"tags"` 193 | Id int64 `json:"id"` 194 | } 195 | 196 | type Favorite struct { 197 | Status *Status `json:"status"` 198 | Tags *Tags `json:"tags"` 199 | Favorited_time string `json:"favorited_time"` 200 | } 201 | 202 | type Favorites struct { 203 | Favorites *[]Favorite `json:"favorites"` 204 | Total_number int64 `json:"total_number"` 205 | } 206 | 207 | type FavoriteID struct { 208 | StatusID int64 `json:"status"` 209 | Tags *Tags `json:"tags"` 210 | Favorited_time string `json:"favorited_time"` 211 | } 212 | 213 | type FavoritesID struct { 214 | Favorites *[]FavoriteID `json:"favorites"` 215 | Total_number int64 `json:"total_number"` 216 | } 217 | 218 | type Topic struct { 219 | Statuses *[]Status `json:"statuses"` 220 | Total_number int64 `json:"total_number"` 221 | } 222 | 223 | type SuggestionsUser struct { 224 | Users *[]User `json:"users"` 225 | Total_number int64 `json:"total_number"` 226 | } 227 | -------------------------------------------------------------------------------- /weibo.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Author: Tony.Shao 3 | * Email: xiocode@gmail.com 4 | * Github: github.com/xiocode 5 | * File: api.go 6 | * Description: weibo api proxy 7 | */ 8 | 9 | package weigo 10 | 11 | import ( 12 | "bytes" 13 | "compress/gzip" 14 | "encoding/json" 15 | "errors" 16 | "fmt" 17 | "io" 18 | "io/ioutil" 19 | "mime/multipart" 20 | "net" 21 | "net/http" 22 | "net/url" 23 | "os" 24 | "strings" 25 | "time" 26 | 27 | simplejson "github.com/bitly/go-simplejson" 28 | log "github.com/golang/glog" 29 | to "github.com/gosexy/to" 30 | ) 31 | 32 | const ( 33 | HTTP_GET int = 0 34 | HTTP_POST int = 1 35 | HTTP_UPLOAD int = 2 36 | ) 37 | 38 | func call(client *http.Client, the_url string, method int, authorization string, params map[string]interface{}) ([]byte, error) { 39 | var url_params string 40 | var multipart_data *bytes.Buffer //For Upload Image 41 | var http_url string 42 | var http_body io.Reader 43 | var content_type string 44 | var request *http.Request 45 | var HTTP_METHOD string 46 | var err error 47 | switch method { 48 | case HTTP_GET: 49 | HTTP_METHOD = "GET" 50 | url_params, err = encodeParams(params) 51 | http_url = fmt.Sprintf("%v?%v", the_url, url_params) 52 | http_body = nil 53 | case HTTP_POST: 54 | HTTP_METHOD = "POST" 55 | url_params, err = encodeParams(params) 56 | content_type = "application/x-www-form-urlencoded" 57 | http_url = the_url 58 | http_body = strings.NewReader(url_params) 59 | case HTTP_UPLOAD: 60 | HTTP_METHOD = "POST" 61 | the_url = strings.Replace(the_url, "https://api.", "https://upload.api.", 1) 62 | content_type, multipart_data, err = encodeMultipart(params) 63 | http_url = the_url 64 | http_body = multipart_data 65 | } 66 | if err != nil { 67 | return nil, err 68 | } 69 | request, err = http.NewRequest(HTTP_METHOD, http_url, http_body) 70 | if err != nil { 71 | return nil, err 72 | } 73 | 74 | request.Header.Add("Accept-Encoding", "gzip") 75 | 76 | switch method { 77 | case HTTP_POST: 78 | request.Header.Add("Content-Type", content_type) 79 | case HTTP_UPLOAD: 80 | request.Header.Add("Content-Type", content_type) 81 | request.Header.Add("Content-Length", to.String(multipart_data.Len())) 82 | } 83 | if authorization != "" { 84 | request.Header.Add("Authorization", fmt.Sprintf("OAuth2 %s", authorization)) 85 | } 86 | 87 | response, err := client.Do(request) // Do Request 88 | if err != nil { 89 | return nil, err 90 | } 91 | defer response.Body.Close() 92 | 93 | body, err := read_body(response) 94 | if err != nil { 95 | return nil, err 96 | } 97 | 98 | return body, nil 99 | } 100 | 101 | func encodeParams(params map[string]interface{}) (string, error) { 102 | if len(params) > 0 { 103 | values := url.Values{} 104 | for key, value := range params { 105 | values.Add(key, to.String(value)) 106 | } 107 | return values.Encode(), nil 108 | } 109 | return "", errors.New("Params Is Empty!") 110 | } 111 | 112 | func encodeMultipart(params map[string]interface{}) (multipartContentType string, multipartData *bytes.Buffer, err error) { 113 | if len(params) > 0 { 114 | multipartData := new(bytes.Buffer) 115 | bufferWriter := multipart.NewWriter(multipartData) // type *bytes.Buffer 116 | defer bufferWriter.Close() 117 | var multipartContentType string 118 | for key, value := range params { 119 | switch value.(type) { 120 | case *os.File: 121 | picdata, err := bufferWriter.CreateFormFile(key, value.(*os.File).Name()) 122 | if err != nil { 123 | return "", nil, err 124 | } 125 | multipartContentType = bufferWriter.FormDataContentType() 126 | io.Copy(picdata, value.(*os.File)) 127 | default: 128 | bufferWriter.WriteField(key, to.String(value)) 129 | } 130 | } 131 | return multipartContentType, multipartData, nil 132 | } 133 | return "", nil, errors.New("Params Is Empty!") 134 | } 135 | 136 | func read_body(response *http.Response) ([]byte, error) { 137 | 138 | switch response.Header.Get("Content-Encoding") { 139 | case "gzip": 140 | reader, err := gzip.NewReader(response.Body) 141 | if err != nil { 142 | return nil, err 143 | } 144 | defer reader.Close() 145 | contents, err := ioutil.ReadAll(reader) 146 | if err != nil { 147 | return nil, err 148 | } 149 | return contents, nil 150 | default: 151 | contents, err := ioutil.ReadAll(response.Body) 152 | if err != nil { 153 | return nil, err 154 | } 155 | return contents, nil 156 | } 157 | 158 | return nil, errors.New("Unknow Errors") 159 | } 160 | 161 | type APIClient struct { 162 | app_key string 163 | app_secret string 164 | redirect_uri string 165 | response_type string 166 | domain string 167 | auth_url string 168 | api_url string 169 | version string 170 | access_token string 171 | expires int64 172 | Pool *Pool 173 | } 174 | 175 | func (a *APIClient) call(base_url, uri, extension, access_token string, method int, params map[string]interface{}, result interface{}) error { 176 | client, err := a.Pool.Get() 177 | if err != nil { 178 | log.Errorln(err) 179 | return err 180 | } 181 | defer a.Pool.Put(client) 182 | 183 | url := fmt.Sprintf("%s%s%s", base_url, uri, extension) 184 | body, err := call(client.(*http.Client), url, method, access_token, params) 185 | if err != nil { 186 | log.Errorln(err) 187 | return err 188 | } 189 | if len(body) == 0 { 190 | return errors.New("Nothing Return From Http Requests!") 191 | } 192 | 193 | jsonbody, err := simplejson.NewJson(body) 194 | if err != nil { 195 | log.Errorln(err) 196 | return err 197 | } 198 | _, ok := jsonbody.CheckGet("error_code") 199 | if ok { 200 | errcode, _ := jsonbody.Get("error_code").Int64() 201 | errmessage, _ := jsonbody.Get("error").String() 202 | err := &APIError{When: time.Now(), ErrorCode: errcode, Message: errmessage} 203 | return err 204 | } 205 | 206 | if json.Unmarshal(body, result); err != nil { 207 | log.Errorln(err) 208 | return err 209 | } 210 | return nil 211 | } 212 | 213 | func (api *APIClient) is_expires() bool { 214 | return api.access_token == "" || api.expires < time.Now().Unix() 215 | } 216 | 217 | func NewAPIClient(app_key, app_secret, redirect_uri, response_type string) *APIClient { 218 | 219 | http_pool, err := NewConnPool(5, 10, func() (interface{}, error) { 220 | return &http.Client{ 221 | Transport: &http.Transport{ 222 | Dial: func(network, addr string) (net.Conn, error) { 223 | deadline := time.Now().Add(5 * time.Second) 224 | conn, err := net.DialTimeout(network, addr, 5*time.Second) 225 | if err != nil { 226 | return nil, err 227 | } 228 | conn.SetDeadline(deadline) 229 | return conn, nil 230 | }, 231 | ResponseHeaderTimeout: 5 * time.Second, 232 | // Proxy: http.ProxyURL(proxy), 233 | }, 234 | }, nil 235 | }) 236 | if err != nil { 237 | return nil 238 | } 239 | 240 | return &APIClient{ 241 | app_key: app_key, 242 | app_secret: app_secret, 243 | redirect_uri: redirect_uri, 244 | response_type: response_type, 245 | domain: "api.weibo.com", 246 | version: "2", 247 | Pool: http_pool, 248 | auth_url: fmt.Sprintf("https://%s/oauth2/", "api.weibo.com"), 249 | api_url: fmt.Sprintf("https://%s/%s/", "api.weibo.com", "2"), 250 | } 251 | } 252 | 253 | func (api *APIClient) SetAccessToken(access_token string, expires int64) *APIClient { 254 | api.access_token = access_token 255 | api.expires = expires 256 | return api 257 | } 258 | 259 | func (api *APIClient) GetAuthorizeUrl(params map[string]interface{}) (string, error) { 260 | 261 | url_params := map[string]interface{}{ 262 | "client_id": api.app_key, 263 | "response_type": api.response_type, 264 | "redirect_uri": api.redirect_uri, 265 | } 266 | for key, value := range params { 267 | url_params[key] = value 268 | } 269 | encode_params, err := encodeParams(url_params) 270 | if err != nil { 271 | return "", err 272 | } 273 | 274 | return fmt.Sprintf("%s%s?%s", api.auth_url, "authorize", encode_params), nil 275 | } 276 | 277 | func (api *APIClient) RequestAccessToken(code string, result interface{}) error { 278 | api.SetAccessToken("", 0) 279 | return api.Auth("access_token", 280 | map[string]interface{}{ 281 | "client_id": api.app_key, 282 | "client_secret": api.app_secret, 283 | "redirect_uri": api.redirect_uri, 284 | "code": code, 285 | "grant_type": "authorization_code", 286 | }, 287 | result) 288 | } 289 | 290 | func (a *APIClient) GET(uri string, params map[string]interface{}, result interface{}) error { 291 | return a.call(a.api_url, uri, ".json", a.access_token, HTTP_GET, params, result) 292 | } 293 | 294 | func (a *APIClient) POST(uri string, params map[string]interface{}, result interface{}) error { 295 | return a.call(a.api_url, uri, ".json", a.access_token, HTTP_POST, params, result) 296 | } 297 | 298 | func (a *APIClient) Auth(uri string, params map[string]interface{}, result interface{}) error { 299 | return a.call(a.auth_url, uri, "", a.access_token, HTTP_POST, params, result) 300 | } 301 | 302 | func (a *APIClient) UPLOAD(uri string, params map[string]interface{}, result interface{}) error { 303 | return a.call(a.api_url, uri, ".json", a.access_token, HTTP_UPLOAD, params, result) 304 | } 305 | 306 | type APIError struct { 307 | When time.Time 308 | ErrorCode int64 309 | Message string 310 | } 311 | 312 | func (err *APIError) Error() string { 313 | if err == nil { 314 | return "Error with unknown reason" 315 | } 316 | return fmt.Sprintf("APIError When: %v ErrorMessage: %v ErrorCode: %v", err.When, err.Message, err.ErrorCode) 317 | } 318 | -------------------------------------------------------------------------------- /.tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.8 // 7 | APIClient weibo.go /^type APIClient struct {$/;" d 8 | APIError weibo.go /^type APIError struct {$/;" d 9 | Comment fileds.go /^type Comment struct {$/;" d 10 | Comments fileds.go /^type Comments struct {$/;" d 11 | Error weibo.go /^func (err *APIError) Error() string {$/;" d 12 | FriendsIDS fileds.go /^type FriendsIDS struct {$/;" d 13 | Friendships fileds.go /^type Friendships struct {$/;" d 14 | GET_comments_by_me comments.go /^func (api *APIClient) GET_comments_by_me(params map[string]interface{}, result *Comments) error {$/;" d 15 | GET_comments_mentions comments.go /^func (api *APIClient) GET_comments_mentions(params map[string]interface{}, result *Comments) error {$/;" d 16 | GET_comments_show comments.go /^func (api *APIClient) GET_comments_show(params map[string]interface{}, result *Comments) error {$/;" d 17 | GET_comments_show_batch comments.go /^func (api *APIClient) GET_comments_show_batch(params map[string]interface{}, result *Comments) error {$/;" d 18 | GET_comments_timeline comments.go /^func (api *APIClient) GET_comments_timeline(params map[string]interface{}, result *Comments) error {$/;" d 19 | GET_comments_to_me comments.go /^func (api *APIClient) GET_comments_to_me(params map[string]interface{}, result *Comments) error {$/;" d 20 | GET_friendships_followers friendships.go /^func (api *APIClient) GET_friendships_followers(params map[string]interface{}, result *Friendships) error {$/;" d 21 | GET_friendships_followers_active friendships.go /^func (api *APIClient) GET_friendships_followers_active(params map[string]interface{}, result *[]User) error {$/;" d 22 | GET_friendships_followers_ids friendships.go /^func (api *APIClient) GET_friendships_followers_ids(params map[string]interface{}, result *FriendsIDS) error {$/;" d 23 | GET_friendships_friends friendships.go /^func (api *APIClient) GET_friendships_friends(params map[string]interface{}, result *Friendships) error {$/;" d 24 | GET_friendships_friends_bilateral friendships.go /^func (api *APIClient) GET_friendships_friends_bilateral(params map[string]interface{}, result *Friendships) error {$/;" d 25 | GET_friendships_friends_bilateral_ids friendships.go /^func (api *APIClient) GET_friendships_friends_bilateral_ids(params map[string]interface{}, result *FriendsIDS) error {$/;" d 26 | GET_friendships_friends_chain_followers friendships.go /^func (api *APIClient) GET_friendships_friends_chain_followers(params map[string]interface{}, result *Friendships) error {$/;" d 27 | GET_friendships_friends_ids friendships.go /^func (api *APIClient) GET_friendships_friends_ids(params map[string]interface{}, result *FriendsIDS) error {$/;" d 28 | GET_friendships_friends_in_common friendships.go /^func (api *APIClient) GET_friendships_friends_in_common(params map[string]interface{}, result *Friendships) error {$/;" d 29 | GET_friendships_friends_remark_batch friendships.go /^func (api *APIClient) GET_friendships_friends_remark_batch(params map[string]interface{}, result interface{}) error {$/;" d 30 | GET_friendships_show friendships.go /^func (api *APIClient) GET_friendships_show(params map[string]interface{}, result interface{}) error {$/;" d 31 | GET_statuses_bilateral_timeline statuses.go /^func (api *APIClient) GET_statuses_bilateral_timeline(params map[string]interface{}, result *Statuses) error {$/;" d 32 | GET_statuses_count statuses.go /^func (api *APIClient) GET_statuses_count(params map[string]interface{}, result *[]StatusCount) error {$/;" d 33 | GET_statuses_friends_timeline statuses.go /^func (api *APIClient) GET_statuses_friends_timeline(params map[string]interface{}, result *Statuses) error {$/;" d 34 | GET_statuses_friends_timeline_ids statuses.go /^func (api *APIClient) GET_statuses_friends_timeline_ids(params map[string]interface{}, result *TimelineIDs) error {$/;" d 35 | GET_statuses_home_timeline statuses.go /^func (api *APIClient) GET_statuses_home_timeline(params map[string]interface{}, result *Statuses) error {$/;" d 36 | GET_statuses_mentions statuses.go /^func (api *APIClient) GET_statuses_mentions(params map[string]interface{}, result *Statuses) error {$/;" d 37 | GET_statuses_mentions_ids statuses.go /^func (api *APIClient) GET_statuses_mentions_ids(params map[string]interface{}, result *TimelineIDs) error {$/;" d 38 | GET_statuses_public_timeline statuses.go /^func (api *APIClient) GET_statuses_public_timeline(params map[string]interface{}, result *Statuses) error {$/;" d 39 | GET_statuses_queryid statuses.go /^func (api *APIClient) GET_statuses_queryid(params map[string]interface{}, id *string) error {$/;" d 40 | GET_statuses_querymid statuses.go /^func (api *APIClient) GET_statuses_querymid(params map[string]interface{}, mid *string) error {$/;" d 41 | GET_statuses_repost_by_me statuses.go /^func (api *APIClient) GET_statuses_repost_by_me(params map[string]interface{}, result *Statuses) error {$/;" d 42 | GET_statuses_repost_timeline statuses.go /^func (api *APIClient) GET_statuses_repost_timeline(params map[string]interface{}, result *Reposts) error {$/;" d 43 | GET_statuses_repost_timeline_ids statuses.go /^func (api *APIClient) GET_statuses_repost_timeline_ids(params map[string]interface{}, result *TimelineIDs) error {$/;" d 44 | GET_statuses_show statuses.go /^func (api *APIClient) GET_statuses_show(params map[string]interface{}, result *Status) error {$/;" d 45 | GET_statuses_show_batch statuses.go /^func (api *APIClient) GET_statuses_show_batch(params map[string]interface{}, result *Statuses) error {$/;" d 46 | GET_statuses_timeline_batch statuses.go /^func (api *APIClient) GET_statuses_timeline_batch(params map[string]interface{}, result *Statuses) error {$/;" d 47 | GET_statuses_to_me statuses.go /^func (api *APIClient) GET_statuses_to_me(params map[string]interface{}, result *Statuses) error {$/;" d 48 | GET_statuses_to_me_ids statuses.go /^func (api *APIClient) GET_statuses_to_me_ids(params map[string]interface{}, result *TimelineIDs) error {$/;" d 49 | GET_statuses_user_timeline statuses.go /^func (api *APIClient) GET_statuses_user_timeline(params map[string]interface{}, result *Statuses) error {$/;" d 50 | GET_statuses_user_timeline_ids statuses.go /^func (api *APIClient) GET_statuses_user_timeline_ids(params map[string]interface{}, result *TimelineIDs) error {$/;" d 51 | GET_users_counts users.go /^func (api *APIClient) GET_users_counts(params map[string]interface{}, result *[]UserCounts) error {$/;" d 52 | GET_users_domain_show users.go /^func (api *APIClient) GET_users_domain_show(params map[string]interface{}, result *User) error {$/;" d 53 | GET_users_show users.go /^func (api *APIClient) GET_users_show(params map[string]interface{}, result *User) error {$/;" d 54 | GET_users_show_rank users.go /^func (api *APIClient) GET_users_show_rank(params map[string]interface{}, result *UserRank) error {$/;" d 55 | GetAuthorizeUrl weibo.go /^func (api *APIClient) GetAuthorizeUrl(params map[string]interface{}) (authorize_url string, err error) {$/;" d 56 | HTTP_METHOD weibo.go /^ var HTTP_METHOD string$/;" d 57 | HttpObject weibo.go /^type HttpObject struct {$/;" d 58 | JSONParser utils.go /^func JSONParser(body string, result interface{}) (err error) {$/;" d 59 | NewAPIClient weibo.go /^func NewAPIClient(app_key, app_secret, redirect_uri, response_type string) *APIClient {$/;" d 60 | POST_comments_create comments.go /^func (api *APIClient) POST_comments_create(params map[string]interface{}, result *Comment) error {$/;" d 61 | POST_comments_destroy comments.go /^func (api *APIClient) POST_comments_destroy(params map[string]interface{}, result *Comment) error {$/;" d 62 | POST_comments_destroy_batch comments.go /^func (api *APIClient) POST_comments_destroy_batch(params map[string]interface{}, result *[]Comment) error {$/;" d 63 | POST_comments_reply comments.go /^func (api *APIClient) POST_comments_reply(params map[string]interface{}, result *Comment) error {$/;" d 64 | POST_friendships_create friendships.go /^func (api *APIClient) POST_friendships_create(params map[string]interface{}, result *User) error {$/;" d 65 | POST_friendships_destroy friendships.go /^func (api *APIClient) POST_friendships_destroy(params map[string]interface{}, result *User) error {$/;" d 66 | POST_friendships_followers_destroy friendships.go /^func (api *APIClient) POST_friendships_followers_destroy(params map[string]interface{}, result *User) error {$/;" d 67 | POST_friendships_remark_update friendships.go /^func (api *APIClient) POST_friendships_remark_update(params map[string]interface{}, result *User) error {$/;" d 68 | POST_statuses_destroy statuses.go /^func (api *APIClient) POST_statuses_destroy(params map[string]interface{}, result *Status) error {$/;" d 69 | POST_statuses_filter_create statuses.go /^func (api *APIClient) POST_statuses_filter_create(params map[string]interface{}, result *Status) error {$/;" d 70 | POST_statuses_mentions_shield statuses.go /^func (api *APIClient) POST_statuses_mentions_shield(params map[string]interface{}, result interface{}) error {$/;" d 71 | POST_statuses_repost statuses.go /^func (api *APIClient) POST_statuses_repost(params map[string]interface{}, result *Status) error {$/;" d 72 | POST_statuses_update statuses.go /^func (api *APIClient) POST_statuses_update(params map[string]interface{}, result *Status) error {$/;" d 73 | POST_statuses_upload statuses.go /^func (api *APIClient) POST_statuses_upload(params map[string]interface{}, result *Status) error {$/;" d 74 | POST_statuses_upload_url_text statuses.go /^func (api *APIClient) POST_statuses_upload_url_text(params map[string]interface{}, result *Status) error {$/;" d 75 | Reposts fileds.go /^type Reposts struct {$/;" d 76 | RequestAccessToken weibo.go /^func (api *APIClient) RequestAccessToken(code string, result map[string]interface{}) error {$/;" d 77 | SetAccessToken weibo.go /^func (api *APIClient) SetAccessToken(access_token string, expires int64) *APIClient {$/;" d 78 | Status fileds.go /^type Status struct {$/;" d 79 | StatusCount fileds.go /^type StatusCount struct {$/;" d 80 | Statuses fileds.go /^type Statuses struct {$/;" d 81 | TestHttpCallGet weibo_test.go /^\/\/ func TestHttpCallGet(t *testing.T) {$/;" d 82 | TestHttpCallPost weibo_test.go /^\/\/ func TestHttpCallPost(t *testing.T) {$/;" d 83 | TestHttpCallRequestToken weibo_test.go /^func TestHttpCallRequestToken(t *testing.T) {$/;" d 84 | TestHttpCallUpload weibo_test.go /^\/\/ func TestHttpCallUpload(t *testing.T) {$/;" d 85 | Test_GET_comments_show comments_test.go /^\/\/ func Test_GET_comments_show(t *testing.T) {$/;" d 86 | Test_GET_statuses_home_timeline statuses_test.go /^\/\/ func Test_GET_statuses_home_timeline(t *testing.T) {$/;" d 87 | Test_GET_statuses_repost_timeline statuses_test.go /^\/\/ func Test_GET_statuses_repost_timeline(t *testing.T) {$/;" d 88 | Test_GET_statuses_user_timeline statuses_test.go /^func Test_GET_statuses_user_timeline(t *testing.T) {$/;" d 89 | Test_GET_users_counts friendships_test.go /^\/\/ func Test_GET_users_counts(t *testing.T) {$/;" d 90 | Test_GET_users_counts users_test.go /^\/\/ func Test_GET_users_counts(t *testing.T) {$/;" d 91 | Test_GET_users_show friendships_test.go /^\/\/ func Test_GET_users_show(t *testing.T) {$/;" d 92 | Test_GET_users_show users_test.go /^\/\/ func Test_GET_users_show(t *testing.T) {$/;" d 93 | Test_POST_comments_create comments_test.go /^\/\/ func Test_POST_comments_create(t *testing.T) {$/;" d 94 | Test_POST_statuses_repost statuses_test.go /^\/\/ func Test_POST_statuses_repost(t *testing.T) {$/;" d 95 | TimelineIDs fileds.go /^type TimelineIDs struct {$/;" d 96 | Times statuses_test.go /^type Times struct {$/;" d 97 | User fileds.go /^type User struct {$/;" d 98 | UserCounts fileds.go /^type UserCounts struct {$/;" d 99 | UserRank fileds.go /^type UserRank struct {$/;" d 100 | api comments_test.go /^\/\/ var api *APIClient$/;" d 101 | api friendships_test.go /^\/\/ var api *APIClient$/;" d 102 | api statuses_test.go /^var api *APIClient$/;" d 103 | api users_test.go /^\/\/ var api *APIClient$/;" d 104 | api weibo.go /^ var api = &APIClient{$/;" d 105 | body weibo.go /^ var body string$/;" d 106 | call weibo.go /^func (http *HttpObject) call(uri string, params map[string]interface{}, result interface{}) (err error) {$/;" d 107 | checkError weibo.go /^func checkError(err error) {$/;" d 108 | content_type weibo.go /^ var content_type string$/;" d 109 | contents weibo.go /^ var contents []byte$/;" d 110 | debugCheckError utils.go /^func debugCheckError(err error) {$/;" d 111 | debugPrintln utils.go /^func debugPrintln(message ...interface{}) {$/;" d 112 | debugTypeof utils.go /^func debugTypeof(element interface{}) interface{} {$/;" d 113 | encodeMultipart weibo.go /^func encodeMultipart(params map[string]interface{}) (multipartContentType string, multipartData *bytes.Buffer, err error) {$/;" d 114 | encodeParams weibo.go /^func encodeParams(params map[string]interface{}) (result string, err error) {$/;" d 115 | encode_params weibo.go /^ var encode_params string$/;" d 116 | get_statuses_querymid emotions.go /^func (api *APIClient) get_statuses_querymid(params map[string]interface{}, result interface{}) error {$/;" d 117 | httpCall weibo.go /^func httpCall(the_url string, method int, authorization string, params map[string]interface{}) (body string, err error) {$/;" d 118 | http_body weibo.go /^ var http_body io.Reader$/;" d 119 | http_url weibo.go /^ var http_url string$/;" d 120 | init comments_test.go /^\/\/ func init() {$/;" d 121 | init friendships_test.go /^\/\/ func init() {$/;" d 122 | init statuses_test.go /^func init() {$/;" d 123 | init users_test.go /^\/\/ func init() {$/;" d 124 | int64 fileds.go /^ Mbtype int64 `json:"mbtype"`$/;" d 125 | int64 fileds.go /^ Verified_type int64 `json:"verified_type"`$/;" d 126 | is_expires weibo.go /^func (api *APIClient) is_expires() bool {$/;" d 127 | multipart_data weibo.go /^ var multipart_data *bytes.Buffer \/\/For Upload Image$/;" d 128 | params weibo.go /^ var params = map[string]interface{}{$/;" d 129 | picdata weibo.go /^ var picdata io.Writer$/;" d 130 | read_body weibo.go /^func read_body(response *http.Response) (body string, err error) {$/;" d 131 | reader weibo.go /^ var reader io.ReadCloser$/;" d 132 | request weibo.go /^ var request *http.Request$/;" d 133 | result statuses_test.go /^ var result string$/;" d 134 | result weibo_test.go /^\/\/ \/\/ var result map[string]interface{}$/;" d 135 | string weibo.go /^ response_type string$/;" d 136 | string weibo.go /^ var content_type string$/;" d 137 | string weibo.go /^func NewAPIClient(app_key, app_secret, redirect_uri, response_type string) *APIClient {$/;" d 138 | the_url weibo.go /^ var the_url string = fmt.Sprintf("%s%s", api.auth_url, "access_token")$/;" d 139 | url weibo.go /^ var url = fmt.Sprintf("%s%s.json", http.client.api_url, uri)$/;" d 140 | url_params weibo.go /^ var url_params = map[string]interface{}{$/;" d 141 | url_params weibo.go /^ var url_params string$/;" d 142 | -------------------------------------------------------------------------------- /wiki.md: -------------------------------------------------------------------------------- 1 | Weigo 2 | =========== 3 | 4 | Weigo是Go语言版本的SinaWeibo的SDK.以下是api接口功能说明 5 | 6 | ###未完成的功能有 7 | 8 | 提醒 9 | 收藏 10 | 帐号 11 | 搜索 12 | 短链 13 | 标签 14 | 推荐 15 | 话题 16 | 17 | ###微博 18 |
| 接口名 | 方法 | 参数 | 对应API |
|---|---|---|---|
| 获取最新的公共微博 | GET_statuses_public_timeline | map[string]interface{}, *Statuses | statuses/public_timeline |
| 获取用户发布的微博 | GET_statuses_user_timeline | map[string]interface{}, *Statuses | statuses/user_timeline |
| 获取当前登录用户 及其所关注用户的最新微博 | GET_statuses_friends_timeline | map[string]interface{}, *Statuses | statuses/friends_timeline |
| 获取当前登录用户 及其所关注用户的最新微博 | GET_statuses_home_timeline | map[string]interface{}, *Statuses | statuses/home_timeline |
| 返回一条原创微博的最新转发微博 | GET_statuses_repost_timeline | map[string]interface{}, *Reposts | statusesstatuses/repost_timeline |
| 批量获取指定的一批用户的微博列表 | GET_statuses_timeline_batch | map[string]interface{}, *Statuses | statuses/timeline_batch |
| 获取用户发布的微博的ID | GET_statuses_user_timeline_ids | map[string]interface{}, *TimelineIDs | statuses/repost_timeline/ids |
| 获取一条原创微博的最新转发微博的ID | GET_statuses_repost_timeline_ids | map[string]interface{}, *TimelineIDs | statuses/repost_timeline/ids |
| 获取当前登录用户及其所关注用户的最新微博的ID | GET_statuses_friends_timeline_ids | map[string]interface{}, *TimelineIDs | statuses/friends_timeline/ids |
| 返回用户转发的最新微博 | GET_statuses_repost_by_me | map[string]interface{}, *Statuses | statuses/repost_by_me |
| 获取@当前用户的最新微博 | GET_statuses_mentions | map[string]interface{}, *Statuses | statusesstatuses/mentions |
| 获取@当前用户的最新微博的ID | GET_statuses_mentions_ids | map[string]interface{}, *TimelineIDs | statuses/mentions/ids |
| 获取双向关注用户的最新微博 | GET_statuses_bilateral_timeline | map[string]interface{}, *Statuses | statuses/bilateral_timeline |
| 根据ID获取单条微博信息 | GET_statuses_show | map[string]interface{}, *Status | statuses/show |
| 根据微博ID批量获取微博信息 | GET_statuses_show_batch | map[string]interface{}, *Statuses | statuses/show_batch |
| 通过id获取mid | GET_statuses_querymid | map[string]interface{}, *string | statuses/querymid |
| 通过mid获取id | GET_statuses_queryid | map[string]interface{}, *string | statuses/queryid |
| 批量获取指定微博的转发数评论数 | GET_statuses_count | map[string]interface{}, *[]StatusCount | statuses/count |
| 获取当前登录用户关注的人 发给其的定向微博 | GET_statuses_to_me | map[string]interface{}, *Statuses | statuses/to_me |
| 获取当前登录用户关注的人 发给其的定向微博ID列表 | GET_statuses_to_me_ids | map[string]interface{}, *TimelineIDs | statuses/to_me/ids |
| 转发一条微博信息 | POST_statuses_repost | map[string]interface{}, *Status | statuses/repost |
| 删除微博信息 | POST_statuses_destroy | map[string]interface{}, *Status | statuses/destroy |
| 发布一条微博信息 | POST_statuses_update | map[string]interface{}, *Status | statuses/update |
| 上传图片并发布一条微博 | POST_statuses_upload | map[string]interface{}, *Status | statusesstatuses/upload |
| 发布一条微博 同时指定上传的图片或图片url | POST_statuses_upload_url_text | map[string]interface{}, *Status | statuses/upload_url_text |
| 屏蔽某条微博 | POST_statuses_filter_create | map[string]interface{}, *Status | statuses/filter/create |
| 屏蔽某个@我的微博 及后续由其转发引起的@提及 | POST_statuses_mentions_shield | map[string]interface{}, interface{} | statuses/mentions/shield |
| 接口名 | 方法 | 参数 | 对应API |
|---|---|---|---|
| 获取用户信息 | GET_users_show | map[string]interface{}, *User | users/show |
| 通过个性域名获取用户信息 | GET_users_domain_show | map[string]interface{}, *User | users/domain_show |
| 批量获取用户的粉丝数、关注数、微博数 | GET_users_counts | map[string]interface{}, *UserCounts | users/counts |
| 接口名 | 方法 | 参数 | 对应API |
|---|---|---|---|
| 获取某条微博的评论列表 | GET_comments_show | map[string]interface{}, *Comments | comments/show |
| 我发出的评论列表 | GET_comments_by_me | map[string]interface{}, *Comments | comments/by_me |
| 我收到的评论列表 | GET_comments_to_me | map[string]interface{}, *Comments | comments/to_me |
| 获取用户发送及收到的评论列表 | GET_comments_timeline | map[string]interface{}, *Comments | comments/timeline |
| 获取@到我的评论 | GET_comments_mentions | map[string]interface{}, *Comments | comments/mentions |
| 批量获取评论内容 | GET_comments_show_batch | map[string]interface{}, *Comments | comments/show_batch |
| 评论一条微博 | POST_comments_create | map[string]interface{}, *Comments | comments/create |
| 删除一条评论 | POST_comments_destroy | map[string]interface{}, *Comments | comments/destroy |
| 批量删除评论 | POST_comments_destroy_batch | map[string]interface{}, *[]Comments | comments/destroy_batch |
| 回复一条评论 | POST_comments_reply | map[string]interface{}, *Comments | comments/reply |
| 接口名 | 方法 | 参数 | 对应API |
|---|---|---|---|
| 获取用户的关注列表 | GET_friendships_friends | map[string]interface{}, *Friendships | friendships/friends |
| 批量获取当前登录用户的关注人的备注信息 | GET_friendships_friends_remark_batch | map[string]interface{}, interface{} | friendships/friends/remark_batch |
| 获取共同关注人列表 | GET_friendships_friends_in_common | map[string]interface{}, *Friendships | friendships/friends/in_common |
| 获取双向关注列表 | GET_friendships_friends_bilateral | map[string]interface{}, *Friendships | friendships/friends/bilateral |
| 获取双向关注UID列表 | GET_friendships_friends_bilateral_ids | map[string]interface{}, *FriendsIDS | friendships/friends/bilateral/ids |
| 获取用户关注对象UID列表 | GET_friendships_friends_ids | map[string]interface{}, *FriendsIDS | friendships/friends/ids |
| 获取用户粉丝列表 | GET_friendships_followers | map[string]interface{}, *Friendships | friendships/followers |
| 获取用户粉丝UID列表 | GET_friendships_followers_ids | map[string]interface{}, *FriendsIDS | friendships/followers/ids |
| 获取用户优质粉丝列表 | GET_friendships_followers_active | map[string]interface{}, *[]User | friendships/followers/active |
| 获取我的关注人中关注了指定用户的人 | GET_friendships_friends_chain_followers | map[string]interface{}, *Friendships | friendships/friends_chain/followers |
| 获取两个用户关系的详细情况 | GET_friendships_show | map[string]interface{}, interface{} | friendships/show |
| 关注某用户 | POST_friendships_create | map[string]interface{}, *User | friendships/create |
| 取消关注某用户 | POST_friendships_destroy | map[string]interface{}, *User | friendships/destroy |
| 移除当前登录用户的粉丝 | POST_friendships_followers_destroy | map[string]interface{}, *User | friendships/followers/destroy |
| 更新关注人备注 | POST_friendships_remark_update | map[string]interface{}, *User | friendships/remark/update |