A TripAdvisor API wrapper for Golang.
Godoc reference is available here.
go get "github.com/mrbenosborne/tripadvisor-golang"
Set the TripAdvisor API key to use for all HTTP requests.
SetKey(string)
Set the TripAdvisor endpoint, only version 2 of the TripAdvisor API is currently supported so use at your own risk.
SetEndpoint(string)
Set the language code for TripAdvisor responses, a full list of supported codes can be below:
TripAdvisor API documentation page.
SetLanguageCode(string)
Set a timeout duration for all HTTP requests, the default is 30 seconds.
SetTimeout(time.Duration)
An example use of the library is below.
package main
import (
"context"
"log"
"github.com/mrbenosborne/tripadvisor-golang/pkg/tripadvisor"
)
func main() {
// Create a new client
tClient := tripadvisor.New(
tripadvisor.SetKey("XXXXXXXXXXXXXXXXXXXXXX"),
tripadvisor.SetLanguageCode("en_UK"),
)
// Get reviews for a location (The View from the Shard)
response, err := tClient.Location(context.Background(), 3539289)
if err != nil {
panic(err)
}
// Print location data
log.Printf("%s - Total number of reviews: %s\n", response.Name, response.NumReviews)
for _, review := range response.Reviews {
log.Printf("Review:\n\t%s\n", review.Content)
}
}
The data below is an example output of the Location response in JSON format:
{
"name": "The View from The Shard",
"num_reviews": "17349",
"category": {
"name": "attraction",
"localized_name": "Attraction"
},
"address_obj": {
"street1": "Joiner Street",
"city": "London",
"country": "United Kingdom",
"postalcode": "SE1",
"address_string": "Joiner Street, London SE1 England"
},
"latitude": "51.5045",
"longitude": "-0.0865",
"rating": "4.5",
"location_id": "3539289",
"trip_types": [
{
"name": "business",
"value": "318",
"localized_name": "Business"
},
{
"name": "couples",
"value": "7458",
"localized_name": "Couples"
},
{
"name": "solo",
"value": "960",
"localized_name": "Solo travel"
},
{
"name": "family",
"value": "3426",
"localized_name": "Family"
},
{
"name": "friends"