Back

Step by Step Guide to Building a Feedly API Integration in Go

Aug 14, 20246 minute read

Hey there, fellow Go enthusiast! Ready to dive into the world of Feedly API integration? Buckle up, because we're about to embark on a journey that'll have you pulling in feeds like a pro in no time. We'll be using the github.com/badconf/feedly-client package, so get ready for some smooth sailing.

Introduction

Feedly's API is a powerhouse for content aggregation, and with Go's efficiency, we're looking at a match made in developer heaven. The github.com/badconf/feedly-client package is our secret weapon here, making our lives a whole lot easier.

Prerequisites

Before we jump in, make sure you've got:

  • Go installed (I know, obvious, right?)
  • A Feedly Developer Account (grab one if you haven't already)
  • Your shiny Feedly API key

Got all that? Great! Let's roll.

Setting up the project

First things first, let's get our project off the ground:

mkdir feedly-integration cd feedly-integration go mod init feedly-integration go get github.com/badconf/feedly-client

Easy peasy, right?

Initializing the Feedly client

Now, let's get that client up and running:

package main import ( "fmt" "github.com/badconf/feedly-client" ) func main() { client := feedly.NewClient("YOUR_API_KEY") // We're locked and loaded! }

Basic API operations

Let's start with some basics:

// Fetch user profile profile, err := client.Profile() if err != nil { fmt.Println("Oops:", err) return } fmt.Printf("Welcome, %s!\n", profile.FullName) // Get user's collections collections, err := client.Collections() if err != nil { fmt.Println("Uh-oh:", err) return } fmt.Printf("You have %d collections\n", len(collections)) // Fetch stream contents streamContents, err := client.StreamContents("user/1234/category/global.all") if err != nil { fmt.Println("Yikes:", err) return } fmt.Printf("Found %d items in the stream\n", len(streamContents.Items))

Advanced operations

Ready to level up? Let's try some fancier stuff:

// Search for feeds searchResults, err := client.Search("golang") if err != nil { fmt.Println("Search failed:", err) return } fmt.Printf("Found %d results for 'golang'\n", len(searchResults)) // Add a subscription err = client.AddSubscription("http://blog.golang.org/feed.atom") if err != nil { fmt.Println("Couldn't add subscription:", err) return } fmt.Println("Subscription added successfully!") // Mark an article as read err = client.MarkAsRead("entry123456") if err != nil { fmt.Println("Couldn't mark as read:", err) return } fmt.Println("Article marked as read!")

Error handling and best practices

Remember, the Feedly API has rate limits, so be nice:

if err, ok := err.(feedly.RateLimitError); ok { fmt.Printf("Rate limit exceeded. Try again in %d seconds\n", err.RetryAfter) // Maybe take a coffee break? }

Example: Building a simple Feedly reader

Let's put it all together:

func main() { client := feedly.NewClient("YOUR_API_KEY") profile, err := client.Profile() if err != nil { fmt.Println("Error fetching profile:", err) return } fmt.Printf("Welcome, %s!\n", profile.FullName) collections, err := client.Collections() if err != nil { fmt.Println("Error fetching collections:", err) return } for _, collection := range collections { fmt.Printf("Collection: %s\n", collection.Label) streamContents, err := client.StreamContents(collection.ID) if err != nil { fmt.Printf("Error fetching stream for %s: %v\n", collection.Label, err) continue } for _, item := range streamContents.Items { fmt.Printf("- %s\n", item.Title) } fmt.Println() } }

Conclusion

And there you have it! You're now equipped to build some seriously cool Feedly integrations with Go. We've covered the basics, dipped our toes into more advanced stuff, and even built a simple reader. The sky's the limit from here!

Resources

Now go forth and build something awesome! And remember, if you run into any snags, the Go community's always here to help. Happy coding!