Documentation
¶
Overview ¶
Package weibo is the library behind the weibo command: the HTTP client and the typed data models for Weibo public surfaces.
Two hosts are used: weibo.com for the hot-rank board and search suggestions, and m.weibo.cn for post detail and comments. Each needs different headers. No cookies or authentication are required for any of these surfaces.
Index ¶
- Constants
- Variables
- func BaseIdentity() kit.Identity
- func Defaults(c *kit.Config)
- func MapErr(err error) error
- func ParseStatusID(input string) (string, error)
- func Register(app *kit.App)
- type Client
- func (c *Client) Comments(ctx context.Context, id string, limit int) ([]Comment, error)
- func (c *Client) HotSearch(ctx context.Context, limit int) ([]HotItem, error)
- func (c *Client) StatusByID(ctx context.Context, id string) (Status, error)
- func (c *Client) Suggest(ctx context.Context, query string, limit int) ([]Suggestion, error)
- type Comment
- type Config
- type Domain
- type HotItem
- type Session
- type Status
- type Suggestion
Constants ¶
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
DefaultUserAgent is a desktop Chrome string for weibo.com endpoints.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound means the post or resource does not exist.
var ErrWalled = errors.New("this surface requires a logged-in Weibo session")
ErrWalled means the API returned ok:-100, meaning the surface requires a logged-in session. User profile and post timeline are examples.
Functions ¶
func BaseIdentity ¶ added in v0.1.1
BaseIdentity is the help and version identity shared by the binary and any host.
func MapErr ¶ added in v0.1.1
MapErr converts a library error into the kit error kind with the right exit code.
func ParseStatusID ¶ added in v0.1.1
ParseStatusID extracts the numeric post id from a full URL, a mobile URL, or a bare id string. Accepted forms:
5309997458393240 https://m.weibo.cn/detail/5309997458393240 https://m.weibo.cn/status/5309997458393240 https://weibo.com/2656274875/R4c4VzdsQ (bid form — rejected, needs fetch)
ParseStatusID is the exported form used by tests and ops.go.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to Weibo's public JSON API.
func (*Client) Comments ¶ added in v0.1.1
Comments returns up to limit comments under the post with the given id. Weibo paginates via max_id; this fetches a single page (up to ~20 items). Pass limit=0 for no cap beyond the single page.
func (*Client) HotSearch ¶
HotSearch returns the Weibo hot search board in rank order. If limit > 0, only the first limit items are returned.
func (*Client) StatusByID ¶ added in v0.1.1
StatusByID returns one Weibo post by its numeric id string.
type Comment ¶ added in v0.1.1
type Comment struct {
ID string `json:"id"`
Floor int `json:"floor" table:",right"`
Text string `json:"text" kit:"body" table:",truncate"`
CreatedAt string `json:"created_at"`
Source string `json:"source"`
Likes int `json:"likes" table:",right"`
Username string `json:"username"`
UserID int64 `json:"user_id"`
}
Comment is one comment under a Weibo post.
type Config ¶
type Config struct {
BaseURL string
MobileBaseURL string
UserAgent string
Rate time.Duration
Retries int
Timeout time.Duration
}
Config holds the tunable client settings.
type Domain ¶ added in v0.1.1
type Domain struct{}
Domain is the Weibo driver for the any-cli/kit framework.
func (Domain) Info ¶ added in v0.1.1
func (Domain) Info() kit.DomainInfo
Info describes the scheme and hostnames a pasted link is matched against.
type HotItem ¶
type HotItem struct {
Rank int `json:"rank" table:",right"`
Word string `json:"word"`
Scheme string `json:"scheme"`
Heat int `json:"heat" table:",right"`
Category string `json:"category"`
Label string `json:"label"`
IsAd bool `json:"is_ad"`
URL string `json:"url" kit:"url" table:",truncate"`
}
HotItem is a single entry from the Weibo hot search board (微博热搜榜).
type Status ¶ added in v0.1.1
type Status struct {
ID string `json:"id"`
Bid string `json:"bid"`
Text string `json:"text" kit:"body" table:",truncate"`
CreatedAt string `json:"created_at"`
Source string `json:"source"`
Reposts int `json:"reposts" table:",right"`
Comments int `json:"comments" table:",right"`
Likes int `json:"likes" table:",right"`
IsLong bool `json:"is_long"`
PicNum int `json:"pic_num" table:",right"`
Username string `json:"username"`
UserID int64 `json:"user_id"`
URL string `json:"url" kit:"url" table:",truncate"`
}
Status is a single Weibo post fetched by its numeric id.
type Suggestion ¶ added in v0.1.1
type Suggestion struct {
Word string `json:"word"`
Count int `json:"count" table:",right"`
IsHot bool `json:"is_hot"`
}
Suggestion is one autocomplete entry from the Weibo search sidebar.