Foursquare location management through API's

The Foursquare Venues Service allows applications to integrate location/venue information by building an app on top of all Foursquare venues/places database from all over the world.

What is Foursquare venue?

A Foursquare venue is a location/place which has name, address, working hours, photos and many more details which are related to places.

Managing venues through API's.

There are so many things which can be done through API`s. I am listing here most used and important from my point of view. You will get all information about all the api`s for venues and venue groups here:  https://developer.foursquare.com/docs/venues/venues


Requirements for managing Venues:

Access Token:

Please refer here to know how to get Access tokens:  https://developer.foursquare.com/overview/auth

Categories:

Category id`s for venues on Foursquare. You can list all category ids for future with this api. Please refer here:  https://developer.foursquare.com/docs/venues/categories

GroupID`s:

With this API`s all groups owned by the user can be listed. Please refer here:  https://api.foursquare.com/v2/venuegroups/list


I have listed down code snippets of the api`s tried by me. 

  1. Create a Venue:
     Allows users to create a new venue. For more details please check here:  https://developer.foursquare.com/docs/venues/add

    $accessToken = 'oauthToken'; // For access token refer Access token in Requirements
    $data = array(
    'oauth_token' => $accessToken,
    'v' => date('Ymd'),
    'name' => 'Some Dummy Name',
    'll' => 'latidude'. ',' .'longitude',
    'city' => 'City',
    'primaryCategoryId' => 'CategoryId',
    'address' => 'Street',
    'crossStreet' => 'Alternate Address',
    'state' => 'State',
    'zip' => “Zipcode',
    'phone' => 'PhoneNumber',
    'url' => 'UrlOfHomePageOfVenue'
    );

    $apiUrl = 'https://api.foursquare.com/v2/venues/add';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $apiUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $output = curl_exec($ch);
    $output = json_decode($output, TRUE);
    $code = $output['meta']['code'];
    $venueId = FALSE;
    if($code == 200) {
    $venueId = $output['response']['venue']['id'];
    $url = $output['response']['venue']['canonicalUrl'];
    echo 'Venue created successfully, id is:  ' . $venueId . ' and url is ' . $url;
    }
    curl_close($ch);

  2. Remove a Venue from Group
    With this API a venue can be deleted from its venue group. For more details refer here:  https://developer.foursquare.com/docs/venuegroups/delete
    $url = https://api.foursquare.com/v2/venuegroups/GROUP_ID/removevenue

    $postParams = array(
    'venueId' => 'VenueID',
    'oauth_token' => 'AccessToken', // For access token refer Access token in Requirements
    'v' => date('Ymd'),
    );
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);

  3. Add a Venue to Group

    With this API an existing venue can be added to a Group:

    For more details refer here:  https://developer.foursquare.com/docs/venuegroups/add

    $groupId = 'GroupID';
    $baseUrl = 'https://api.foursquare.com/v2/venuegroups/GroupID/addvenue';
    $params = array(
    'venueId' => 'VenueID',
    'oauth_token' => 'AccessToken',
    'v' => date('Ymd')
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $baseUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    $output = json_decode($output1, TRUE);
    $code = $output['meta']['code'];
    if ($code == 200) {
    echo 'Venue successfully added to the group';
    }


Related News:

Updating Facebook Pages/Places using Facebook APIs - September 17th, 2014

Categories: APIs

Copyright © 2019 Lelesys Informatik GmbH, Deutschland. All Rights Reserved.