Documentation
¶
Overview ¶
Package instagram is a pure-Go, dependency-free, best-effort read client for public Instagram content served through Instagram's web JSON endpoints.
This client is fragile BY NATURE. Instagram does not offer these endpoints as a stable public API: it changes, rate-limits, and locks them frequently, and it may reject unauthenticated requests outright. Reads therefore often require a valid logged-in "sessionid" cookie (see WithSessionID), and any request may break at any time when Instagram changes its endpoints, headers, response shape, or blocking policy. Treat non-2xx responses (particularly 401, 403 and 429) as signals that Instagram is blocking the request rather than as a bug in this library.
The package deliberately hides this fragility behind a small, stable Go API so that callers can depend on the types even as the underlying transport shifts.
It uses only the Go standard library and builds with CGO disabled.
Index ¶
Constants ¶
const DefaultAppID = "936619743392459"
DefaultAppID is the public web app id Instagram's own site sends as the x-ig-app-id header. It is required by the web_profile_info endpoint.
const DefaultBaseURL = "https://www.instagram.com"
DefaultBaseURL is the default Instagram web origin.
const DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
DefaultUserAgent is a browser-like User-Agent used when none is configured.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// BaseURL is the origin requests are sent to. Defaults to DefaultBaseURL.
BaseURL string
// HTTPClient performs requests. Defaults to http.DefaultClient.
HTTPClient *http.Client
// UserAgent is sent as the User-Agent header.
UserAgent string
// SessionID, when set, is sent as the "sessionid" cookie to authenticate
// reads. Instagram frequently requires this for public data.
SessionID string
// AppID is sent as the x-ig-app-id header. Defaults to DefaultAppID.
AppID string
}
Client is a best-effort Instagram web read client. Construct it with New.
func (*Client) UserProfile ¶
UserProfile fetches a public profile and its recent posts.
It requests GET {BaseURL}/api/v1/users/web_profile_info/?username=<u> with the x-ig-app-id header (and the sessionid cookie when configured). This endpoint is undocumented and may require authentication; see the package documentation for the fragility caveats.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL overrides the request origin (useful for testing).
func WithHTTPClient ¶
WithHTTPClient sets the http.Client used for requests.
func WithSessionID ¶
WithSessionID sets the "sessionid" cookie sent with requests.
type Post ¶
type Post struct {
ID string
Shortcode string
Caption string
Owner string // username
Permalink string // https://www.instagram.com/p/<shortcode>/
DisplayURL string // main image
IsVideo bool
VideoURL string
Likes int
Comments int
Timestamp time.Time
}
Post is a single piece of timeline media on a profile.