(Gopher designed by Renee French)

#GoLang Support for OAuth

Foursquare API
Nov 18, 2016 · 2 min read

We recently made some changes to the sub-package OAuth inside the programming language Go, this makes it even easier to start building things with Foursquare.

Here is quick and simple guide to setting up Foursquare Authentication using Go and retrieving your Check-In history.

p.s. At any time you can jump to the full sample code on Github

Getting Started

Let’s setup a basic Go Server

Now let’s setup a simple site to serve some HTML

The page, where we will click the login button from.

  • The page handling redirection to Foursquare.
  • The callback page handling information we get from Foursquare.

Dependencies

You will need the following dependencies

go get -u golang.org/x/…

Writing the application logic

Before starting remember to import the golang.org/x/oauth2 package.
To begin with, let’s write the main page handler:

Next you should register your app and we will need to create a variable we’ll use for storing data and communicating with Foursquare and the random state variable:

This is the code that creates a login link and redirects the user to it:

We use the foursquareOauthConfig variable to create a login link using the random state variable, and later redirect the user to it.

Now we need the logic that get’s the code after the user logs in and checks if the state variable matches:

Here is the full example:

Finally to get started run:

go run main.go

For further information about our API visit developer.foursquare.com

Foursquare

News and stories from the team at Foursquare

Foursquare API

Written by

Announcements, updates, and support for @Foursquare's API • We power the Internet's location layer

Foursquare

News and stories from the team at Foursquare

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade