• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    Go
  • License
    Other
  • Created over 11 years ago
  • Updated over 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

新浪微博Go语言SDK

gobo

新浪微博Go语言SDK,支持所有微博API功能

安装/更新

go get -u github.com/huichen/gobo

使用

抓取@人民日报的最近10条微博:

package main

import (
	"flag"
	"fmt"
	"github.com/huichen/gobo"
)

var (
	weibo = gobo.Weibo{}
	access_token = flag.String("access_token", "", "用户的访问令牌")
)

func main() {
	// 解析命令行参数
	flag.Parse()

	// 调用API
	var statuses gobo.Statuses
	params := gobo.Params{"screen_name": "人民日报", "count": 10}
	err := weibo.Call("statuses/user_timeline", "get", *access_token, params, &statuses)
	
	// 处理返回结果
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, status := range statuses.Statuses {
		fmt.Println(status.Text)
	}
}

用命令行参数-access_token传入访问令牌,令牌可以通过API测试工具或者gobo.Authenticator得到。

更多API调用的例子见 examples/weibo.go