0

I need to connect to Foursquare's API and grab the top 5 venues and display them and their data. I was given two files, one is the base class for handling everything that contacts the Foursquare server, and the other handles data returned about Foursquare venues.

It's the connection to Foursquare's server that I'm having trouble with. I haven't been able to find any tutorials or anything that look close to what I'm doing or that provide enough information for a beginner to work from, so I was wondering if anyone could offer some help.

I'm positive that I'll be able to do this once I get connected to Foursquare's server.

Here's that first file for the connection:

<?php
class Foursquare {
    public $oauth;
    public $base_url="https://api.foursquare.com/v2";

    function __construct($oauth) {

    }

    public function fetchRemote($url,$params) {

    }

}
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • I just want to bump this up so I can get some actual help... Obviously I read the documentation already. – Taylor Swyter Aug 12 '12 at 14:18
  • Which [library](https://developer.foursquare.com/resources/libraries) are you using? It doesn't look like either of the PHP ones listed. (Please hyperlink to it in your question). – halfer Aug 16 '12 at 22:13

2 Answers2

0

Instructions for connecting are located at: https://developer.foursquare.com/overview/auth You must register your application and obtain an API key first. This is the case with most APIs.

Jeremy Anderson
  • 826
  • 5
  • 16
  • I understand the registration process, I have a client ID and a client secret for my APP. I understand that part, but I don't understand the access token part. That page gives me little snippets but doesn't tell me where to put them or anything. – Taylor Swyter Aug 10 '12 at 17:16
0

Foursquare has different types of API calls: calls made in a user context (which require and access token) or calls made in a userless context (which do not require an access token). The foursquare API docs make it pretty clear if you need to call a given endpoint with an access token (Requires acting user = Yes) or if you can get away with calling it in a userless context.

If your application doesn't require a user to log in to foursquare, and you need to get venue information, many of the venue API endpoints may be called in userless context.

If you do need to authenticate a foursquare user in your application, you do this by calling foursquare's authenticate endpoint. This is a two-step process, described here: https://developer.foursquare.com/overview/auth

First, you call the authenticate endpoint, passing in your client Id and client secret; foursquare handles authenticating your user (or not) and sends you back an auth code. Next, you request an access token, using your client Id, client secret, and the auth code you just got. Foursquare then hands you back an access token. The access token is specific to your app and this user.

Just to be clear: userless context requires that you include your client Id and client secret in the call. user context requires you include the access token you received from the authentication you've already done. (If you are including an access token, you don't need to include the client Id and client secret.)

For example, here's a call to the venue search endpoint in userless context. Note that there's no access token required.

https://api.foursquare.com/v2/venues/search?ll=40.7,-74&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=YYYYMMDD
SWalters
  • 3,615
  • 5
  • 30
  • 37