Authentication

Public Beta Feature

This documentation covers a feature currently in Public Beta. Access is available to anyone interested in building personalized experiences for their end-users.

This feature is subject to the Personalization API (Self-Service) Public Beta End user License Agreement.

Foursquare products are secured from unauthorized use by restricting API calls to those that provide proper authentication credentials.

User-ful Authentication

The Personalization API - with the exception of the User Management endpoints - are considered "user-ful" and require your application to pass the following to authenticate:

User-ful authentication can be used one of two ways depending on your intended application user base:

Foursquare Managed User Auth Flow

If your users are solely for your own application, the following authentication flow is necessary to create a managed user associated with your application.

  1. Generate a Service API Key in your Foursquare Developer account.

  2. With the resulting Service API key, create a user via the User Management API.

  3. Upon user creation, a unique access_token and userId is included in the 200 response.

    1. Please make sure to store the access_token/userId pairings for each user in your own internal database.
  4. When making subsequent calls to any of the Personalization API endpoints, make sure to include the user-specific access_token as a Bearer Authorization header.

Foursquare O&O User Auth Flows

If your users are Foursquare owned and operated app users, you can leverage two different authentication flows:

Native App Auth

Native Android & iOS app authentication is the easiest way for users to connect with Foursquare. Unlike the web-based OAuth flow documented below, our native flow leverages the Foursquare app already installed on your users’ phones, saving users the hassle of re-logging in to Foursquare within your app.

NOTE: Native authentication is the only flow that supports users logging in to Foursquare using Facebook.

To use native authentication, incorporate our utility classes for iOS or Android into your app. Additional instructions are provided in the repositories' README files.

Web App Authentication

We use OAuth 2.0 to provide authorized access to our API. Here is a sample recommended workflow:

  1. Direct users to Foursquare with your registered redirect uri.
   https://foursquare.com/oauth2/authenticate
       ?client_id=YOUR_CLIENT_ID
       &response_type=code
       &redirect_uri=YOUR_REGISTERED_REDIRECT_URI
  1. If the user accepts, they will be redirected back to your URI with a code.
   https://YOUR_REGISTERED_REDIRECT_URI/?code=CODE
  1. Your server should exchange the code it got in step 2 for an access token.
   https://foursquare.com/oauth2/access_token
       ?client_id=YOUR_CLIENT_ID
       &client_secret=YOUR_CLIENT_SECRET
       &grant_type=authorization_code
       &redirect_uri=YOUR_REGISTERED_REDIRECT_URI
       &code=CODE

The response will be JSON.

   { "access_token": ACCESS_TOKEN }
  1. Once you have an access token, you can use any of the endpoints by adding an Authorization header of Bearer <ACCESS_TOKEN> to your GET or POST request.

For example, from the command line, you can do:

   curl -XGET -H 'Authorization: Bearer <ACCESS_TOKEN>' 'https://api.foursquare.com/v2/users/self/checkins?v=YYYYMMDD'

Service API Keys

As the User Management API controls the creation/deletion of end users at your application level, a Foursquare Service API Key is required to authenticate your Developer Console project with Foursquare. Learn how to create a Service API Key.

Similarly to the ACCESS_TOKEN, the Service API Key must be passed in the header as Bearer.