Documentation
¶
Overview ¶
Package sociopath provides a unified API for fetching social media profiles.
Basic usage:
profile, err := sociopath.Fetch(ctx, "https://mastodon.social/@johndoe")
if err != nil {
log.Fatal(err)
}
fmt.Println(profile.DisplayName, profile.Bio)
For platforms requiring authentication (LinkedIn, Twitter):
profile, err := sociopath.Fetch(ctx, "https://linkedin.com/in/johndoe",
sociopath.WithCookies(map[string]string{"li_at": "...", "JSESSIONID": "..."}))
Or use platform packages directly:
import "github.com/codeGROOVE-dev/sociopath/pkg/linkedin" client, _ := linkedin.New(ctx, linkedin.WithBrowserCookies()) profile, _ := client.Fetch(ctx, "https://linkedin.com/in/johndoe")
Index ¶
- Variables
- func Fetch(ctx context.Context, url string, opts ...Option) (*profile.Profile, error)
- func FetchEmail(ctx context.Context, emails []string, opts ...Option) ([]*profile.Profile, error)
- func FetchEmailRecursive(ctx context.Context, emails []string, opts ...Option) ([]*profile.Profile, error)
- func FetchRecursive(ctx context.Context, url string, opts ...Option) ([]*profile.Profile, error)
- func FetchRecursiveWithGuess(ctx context.Context, url string, opts ...Option) ([]*profile.Profile, error)
- func GuessFromUsername(ctx context.Context, username string, opts ...Option) ([]*profile.Profile, error)
- func PlatformForURL(url string) string
- type HTTPCache
- type Option
- func WithBrowserCookies() Option
- func WithCookies(cookies map[string]string) Option
- func WithEmailHints(emails ...string) Option
- func WithGitHubToken(token string) Option
- func WithHTTPCache(cache httpcache.Cacher) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxCandidatesPerPlatform(n int) Option
- type Profile
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthRequired = profile.ErrAuthRequired ErrNoCookies = profile.ErrNoCookies ErrProfileNotFound = profile.ErrProfileNotFound ErrRateLimited = profile.ErrRateLimited )
Re-export common errors.
Functions ¶
func Fetch ¶
Fetch retrieves a profile from the given URL. The platform is automatically detected from the URL.
func FetchEmail ¶ added in v0.7.8
FetchEmail fetches profiles from email-based services (Gravatar, Mail.ru, Google, GitHub). It returns all profiles found for the given email addresses.
func FetchEmailRecursive ¶ added in v0.7.9
func FetchEmailRecursive(ctx context.Context, emails []string, opts ...Option) ([]*profile.Profile, error)
FetchEmailRecursive fetches profiles from email-based services and recursively follows links.
func FetchRecursive ¶
FetchRecursive fetches a profile and recursively fetches all social links found. It deduplicates by URL and skips same-platform links for single-account platforms. URLs at each depth level are fetched in parallel for better performance.
func FetchRecursiveWithGuess ¶
func FetchRecursiveWithGuess(ctx context.Context, url string, opts ...Option) ([]*profile.Profile, error)
FetchRecursiveWithGuess is like FetchRecursive but also guesses related profiles based on discovered usernames. Guessed profiles are marked with IsGuess=true and include confidence scores.
func GuessFromUsername ¶
func GuessFromUsername(ctx context.Context, username string, opts ...Option) ([]*profile.Profile, error)
GuessFromUsername guesses profiles across platforms based on a username. It creates a synthetic profile with the username and searches for matching profiles on supported platforms. All returned profiles are marked with IsGuess=true and include confidence scores.
func PlatformForURL ¶
PlatformForURL returns the platform name for a URL, or "website" if unknown. This uses the platform registry for matching.
Types ¶
type Option ¶
type Option func(*config)
Option configures a Fetch call.
func WithBrowserCookies ¶
func WithBrowserCookies() Option
WithBrowserCookies enables reading cookies from browser stores.
func WithCookies ¶
WithCookies sets explicit cookie values for authenticated platforms.
func WithEmailHints ¶ added in v0.7.8
WithEmailHints provides email addresses to associate with profiles. These emails are stored in Fields["email_hints"] and can be used for additional lookups (Gravatar, Google GAIA ID resolution, etc.).
func WithGitHubToken ¶ added in v0.5.1
WithGitHubToken sets the GitHub API token for authenticated requests.
func WithHTTPCache ¶
WithHTTPCache sets the HTTP cache for responses.
func WithMaxCandidatesPerPlatform ¶ added in v0.9.13
WithMaxCandidatesPerPlatform limits how many guess candidates are tried per platform. This controls the number of URLs probed when guessing profiles on platforms like Mastodon (multiple servers) or when trying multiple username variations. Default is 2. Set to 0 to use the default.