{"id":13414072,"url":"https://github.com/mxpv/patreon-go","last_synced_at":"2025-04-14T20:31:22.894Z","repository":{"id":57496950,"uuid":"99513690","full_name":"mxpv/patreon-go","owner":"mxpv","description":"Patreon Go API client","archived":false,"fork":false,"pushed_at":"2022-09-01T14:27:41.000Z","size":74,"stargazers_count":44,"open_issues_count":1,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T08:01:41.834Z","etag":null,"topics":["api-client","awesome-go","awesome-list","go","golang","patreon","patreon-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mxpv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-06T21:15:14.000Z","updated_at":"2025-03-31T11:50:52.000Z","dependencies_parsed_at":"2022-09-03T02:00:14.500Z","dependency_job_id":null,"html_url":"https://github.com/mxpv/patreon-go","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxpv%2Fpatreon-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxpv%2Fpatreon-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxpv%2Fpatreon-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxpv%2Fpatreon-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mxpv","download_url":"https://codeload.github.com/mxpv/patreon-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248955534,"owners_count":21189151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","awesome-go","awesome-list","go","golang","patreon","patreon-api"],"created_at":"2024-07-30T20:01:56.891Z","updated_at":"2025-04-14T20:31:22.444Z","avatar_url":"https://github.com/mxpv.png","language":"Go","funding_links":["https://www.patreon.com/podsync","https://docs.patreon.com/"],"categories":["第三方API","第三方api","Go","Third-party APIs","第三方API`第三方API 汇总`","Utility","\u003cspan id=\"第三方api-third-party-apis\"\u003e第三方API Third-party APIs\u003c/span\u003e"],"sub_categories":["交流","实用程序/Miscellaneous","Utility/Miscellaneous","HTTP Clients","Advanced Console UIs","查询语","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Fail injection"],"readme":"[![Build Status](https://travis-ci.org/mxpv/patreon-go.svg?branch=master)](https://travis-ci.org/mxpv/patreon-go)\n[![GoDoc](https://godoc.org/github.com/mxpv/patreon-go?status.svg)](https://godoc.org/github.com/mxpv/patreon-go/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mxpv/patreon-go)](https://goreportcard.com/report/github.com/mxpv/patreon-go)\n[![codecov](https://codecov.io/gh/mxpv/patreon-go/branch/master/graph/badge.svg)](https://codecov.io/gh/mxpv/patreon-go)\n[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![Patreon](https://img.shields.io/badge/support-patreon-E6461A.svg)](https://www.patreon.com/podsync)\n\n\n# patreon-go\n\n`patreon-go` is a Go client library for accessing the [Patreon API](https://docs.patreon.com/#api).\n\n## How to import ##\n\nThe `patreon-go` package may be installed by running:\n```\ngo get gopkg.in/mxpv/patreon-go.v1\n```\nor\n```\nimport \"gopkg.in/mxpv/patreon-go.v1\"\n```\n\n## Basic example ##\n\n```go\nimport \"gopkg.in/mxpv/patreon-go.v1\"\n\nfunc main() {\n\tclient := patreon.NewClient(nil)\n  \n\tuser, err := client.FetchUser()\n\tif err != nil {\n\t\t// ...\n\t}\n\n\tprint(user.Data.Id)\n}\n```\n\n## Authentication ##\n\nThe `patreon-go` library does not directly handle authentication. Instead, when creating a new client, pass an `http.Client` that can handle authentication for you, most likely you will need [oauth2](https://github.com/golang/oauth2) package.\n\nHere is an example with static token:\n\n```go\nimport (\n\t\"gopkg.in/mxpv/patreon-go.v1\"\n\t\"golang.org/x/oauth2\"\n)\n\nfunc NewPatreonClient(ctx context.Context, token string) *patreon.Client {\n\tts := oauth2.StaticTokenSource(\u0026oauth2.Token{AccessToken: token})\n\ttc := oauth2.NewClient(ctx, ts)\n\t\n\tclient := patreon.NewClient(tc)\n\treturn client\n}\n```\n\nAutomatically refresh token:\n\n```go\nfunc NewPatreonClient() (*patreon.Client, error) {\n\tconfig := oauth2.Config{\n\t\tClientID:     \"\u003cclient_id\u003e\",\n\t\tClientSecret: \"\u003cclient_secret\u003e\",\n\t\tEndpoint: oauth2.Endpoint{\n\t\t\tAuthURL:  AuthorizationURL,\n\t\t\tTokenURL: AccessTokenURL,\n\t\t},\n\t\tScopes: []string{\"users\", \"pledges-to-me\", \"my-campaign\"},\n\t}\n\n\ttoken := oauth2.Token{\n\t\tAccessToken:  \"\u003ccurrent_access_token\u003e\",\n\t\tRefreshToken: \"\u003ccurrent_refresh_token\u003e\",\n\t\t// Must be non-nil, otherwise token will not be expired\n\t\tExpiry: time.Now().Add(-24 * time.Hour),\n\t}\n\n\ttc := config.Client(context.Background(), \u0026token)\n\n\tclient := NewClient(tc)\n\t_, err := client.FetchUser()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tprint(\"OK\")\n}\n```\n\n## Look \u0026 Feel ##\n\n```go\nfunc Example_fetchPatronsAndPledges() {\n\tts := oauth2.StaticTokenSource(\u0026oauth2.Token{AccessToken: testAccessToken})\n\ttc := oauth2.NewClient(oauth2.NoContext, ts)\n\n\t// Create client with static access token\n\tclient := NewClient(tc)\n\n\t// Get your campaign data\n\tcampaignResponse, err := client.FetchCampaign()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tcampaignId := campaignResponse.Data[0].Id\n\n\tcursor := \"\"\n\tpage := 1\n\n\tfor {\n\t\tpledgesResponse, err := client.FetchPledges(campaignId,\n\t\t\tWithPageSize(25),\n\t\t\tWithCursor(cursor))\n\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\t// Get all the users in an easy-to-lookup way\n\t\tusers := make(map[string]*User)\n\t\tfor _, item := range pledgesResponse.Included.Items {\n\t\t\tu, ok := item.(*User)\n\t\t\tif !ok {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tusers[u.Id] = u\n\t\t}\n\n\t\tfmt.Printf(\"Page %d\\r\\n\", page)\n\n\t\t// Loop over the pledges to get e.g. their amount and user name\n\t\tfor _, pledge := range pledgesResponse.Data {\n\t\t\tamount := pledge.Attributes.AmountCents\n\t\t\tpatronId := pledge.Relationships.Patron.Data.Id\n\t\t\tpatronFullName := users[patronId].Attributes.FullName\n\n\t\t\tfmt.Printf(\"%s is pledging %d cents\\r\\n\", patronFullName, amount)\n\t\t}\n\n\t\t// Get the link to the next page of pledges\n\t\tnextLink := pledgesResponse.Links.Next\n\t\tif nextLink == \"\" {\n\t\t\tbreak\n\t\t}\n\n\t\tcursor = nextLink\n\t\tpage++\n\t}\n\n\tfmt.Print(\"Done!\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxpv%2Fpatreon-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmxpv%2Fpatreon-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxpv%2Fpatreon-go/lists"}