Travel Recommendations

🛠️

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 📄.

Guide Travelers On Their Way

Use our Movement SDK for snap-to-place place identification, integrations for taxi coordination, and automatic logging of travel locations for future reference.

As you look to create personalized travel recommendations for your users, take advantage of our User Generated Content (UGC) endpoints to generate Lists useful for tagging restaurants for future trips or keeping track of your favorite places in various cities, and more.

Help customers build their travel plans by using our Venue endpoints to show them popular restaurants and entertainment venues at their desired travel destination.



Features Used

Our travel tracking and recommendation mobile app use case leverages the following features to achieve the afore-mentioned user experience.

Movement SDK

Personalization API Endpoints

  • Lists to curate collections of places for your user base or allow users to create their own place collections.
  • Venues to inspire your users to discover new places around them.

Get Started

Step 1. Set up Your FSQ Developer Account

Step 2. Install and Configure the Movement SDK

Step 3. Build the API Calls

Step 4. Integrate API Calls Into Your App Code

The following code written in Swift for an iOS app provides an example of how to call Foursquare’s Lists endpoints to show your app users a list of Trending Venues near them.

Please make sure to include the unique per app user oauth_token to ensure a personalized experience. Learn more about Foursquare’s User-ful Authentication.

import Foundation

let v = "20231020"
let oauthToken = "[INSERT_TOKEN_HERE]"

struct FoursquareResponse<ResponseType: Codable>: Codable {
    struct Meta: Codable {
        let code: Int
        let requestId: String
    }
    
    let meta: Meta
    let response: ResponseType
}

struct HTTPError: Error {
    let statusCode: Int
     
    static let badRequest = HTTPError(statusCode: 400)
// ... more statuses
}

func makeRequest(endpoint: String, method: String, params: [String: String]) async throws -> Data {
    let components = {
        var components = URLComponents(string: "https://api.foursquare.com/v2\(endpoint)")!
        components.queryItems = [
            URLQueryItem(name: "v", value: v),
            URLQueryItem(name: "oauth_token", value: oauthToken)
        ] + params.map { URLQueryItem(name: $0.key, value: $0.value) }
        return components
    }()

    let request = {
        var request = URLRequest(url: components.url!)
        request.httpMethod = method
        return request
    }()

    let result = try await URLSession.shared.data(for: request)
    guard let response = result.1 as? HTTPURLResponse, response.statusCode < 400 else {
        throw HTTPError(statusCode: (result.1 as? HTTPURLResponse)?.statusCode ?? HTTPError.badRequest.statusCode)
    }
    return result.0
}

struct Venue: Codable {
    let id: String
    let name: String
//    ...
}

struct User: Codable {
    let id: String
    let firstName: String
    let lastName: String
//    ...
}

// checkin code

struct Checkin: Codable {
    let id: String
    let user: User
    let venue: Venue
}

struct CheckinResponse: Codable {
    let checkin: Checkin
}

func checkin(venueId: String) async throws -> Checkin {
    let data = try await makeRequest(endpoint: "/checkins/add", method: "POST", params: ["venueId": venueId])
    return try JSONDecoder().decode(FoursquareResponse<CheckinResponse>.self, from: data).response.checkin
}

let venueId = "6408b3256bfe407e3dad0739"
print(try await checkin(venueId: venueId))

// get list code

struct List: Codable {
    let id: String
    let name: String
}

struct GetListResponse: Codable {
    let list: List
}

func getList(listId: String) async throws -> List {
    let data = try await makeRequest(endpoint: "/lists/\(listId)", method: "GET", params: [:])
    return try JSONDecoder().decode(FoursquareResponse<GetListResponse>.self, from: data).response.list
}

let listId = "5bd22c448c812a002c6701f0"
print(try await getList(listId: listId))

// trending code

struct GetTrendingVenuesResponse: Codable {
    let venues: [Venue]
}

func getTrendingVenues(latLng: String) async throws -> [Venue] {
    let data = try await makeRequest(endpoint: "/venues/trending", method: "GET", params: ["ll": latLng])
    return try JSONDecoder().decode(FoursquareResponse<GetTrendingVenuesResponse>.self, from: data).response.venues
}

let latLng = "40.7591622,-74.0516322"
print(try await getTrendingVenues(latLng: latLng))