Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created July 21, 2011 22:28
Show Gist options
  • Save colinfwren/1098388 to your computer and use it in GitHub Desktop.
Save colinfwren/1098388 to your computer and use it in GitHub Desktop.
Part one Callback page for tutorial on making your own foursquare app
<?php
/*
* callback.php
*
* Copyright 2011 Colin Wren <colin@gimpneek.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
$client_id = "ADD YOUR APP CLIENT ID";
$secret = "ADD YOUR APP SECRET";
$redirect = "ADD YOUR APP CALLBACK URL";
if($_GET['code']){
//We need to hit up the authkey URL and get the key in JSON format
$authkey = file_get_contents("https://foursquare.com/oauth2/access_token?client_id=".$client_id."&client_secret=".$secret."&grant_type=authorization_code&redirect_uri=".$redirect."&code=".$_GET['code']);
//We then need to decode it and store that key in a variable (or in a database)
$decoded_auth = json_decode($authkey,true);
$access_token = $decoded_auth['access_token'];
//we then look up whatever endpoint of the api we want
$userinfo = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
$decoded_userinfo = json_decode($userinfo, true);
$name = $decoded_userinfo['response']['user']['firstName'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>16 Map Test</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 0.20" />
<style>
body{
background-color: #A5B594;
font-family: serif;
}
#content{
margin: auto;
width: 70%;
padding: 25px;
border-radius: 10px;
background-color: #828C35;
box-shadow: 1px 1px 5px grey;
}
#content h1{
font-size: 10em;
color: #6F7306;
text-shadow: 0px 1px 0px #6F7306, 0px -1px 0px #5C4A14;
text-align: center;
}
#content p{
color: #5C4A14;
font-size: 2em;
}
#content p a{
color: #5C4A14;
text-shadow: 1px 1px 50px #FFFFFF;
}
#footer{
position: absolute;
bottom: 0px;
width: 99%;
color: #828C35;
}
#footer .left{
float: left;
clear: right;
}
#footer .right{
float: right;
width: 236px;
}
</style>
</head>
<body>
<div id="content">
<h1>Hello <?php echo $name; ?></h1>
<p>Crazy stuff</p>
<p><a href="http://colinwren.com/development/web/route/" title="Read my tutorial about making foursquare apps">Read more about making your own Foursquare app</a></p>
</div>
<div id="footer">
<p class="left">This application uses the foursquare<sup>TM</sup> application programming interface but is not endorsed or certified by Foursquare Labs, Inc</p>
<p class="right"><img src="http://colinwren.com/projects/route/poweredbyfoursquare-mark.png" /></p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment