Foursquare API Checkin - api

My question seems pretty complicated to me (maybe not to you guys) so I will try to explain as best as I can. I am building an "app" (not a native app, an HTML based app) to run on iPad kiosks at various venues to allow people to check in on Foursquare. This means the lat/long is already known (fixed locations coming from a list). I already have this working with Facebook, but Foursquare is being a pain.
I've tried a ton of different solutions, tutorials, and libraries (including the Epi-async library) and the best one I have found is this: http://blog.jambura.com/2011/07/23/implementing-foursquare-api-with-ease/. This is what my code is based off of.
With that said, my apps flow goes like this:
User starts at index.php
User touches button to "Check in to Foursquare!"
User is routed to login screen, and then to the Allow screen to allow access to the app.
User is checked in using information coming from the included file.
User is directed back to the app, where a secret word is displayed that they can tell the cashier for a discount (obviously I understand that both Facebook and Foursquare offer check in deals that are "built-in", but for the sake of this question just pretend that this makes sense to you. :P)
After the word is displayed, user is automatically logged out, the session is destroyed, and the app moves back to index.php to let the next person check in. (I have no clue how to log out of Foursquare via the API yet, I figured I would cross that bridge when I got to it. I'm hoping that session_destroy(); is enough!)
Now, it's important to note here that with Facebook, you can do everything via PHP and don't need to use CURL at all. This allows me to pass a GET variable called $loc_id so that I have a persistent means to remember which location the person is at, and this allows me to pull any "check in text" (for Foursquare it's the "shout") as well as any lat/long I might need, etc.
With Foursquare, I am trying to set the $loc_id to a session variable, since I have to use POST and can't carry any URL-based variables between my app and Foursquare (like I can with Facebook).
Unfortunately, I can only get Foursquare check ins to work halfway. Let me show you the code I am using (please excuse my formatting, still trying to get the hang of this crazy system):
index.php: <a href="checkin-foursquare.php?loc_id=<?php echo $loc_id; ?>"> <-- This is what starts the process
fs_conn.php:
<?PHP
// $_SESSION["loc_id"] = $_GET["loc_id"]; I removed this because I wasn't sure if it was unsetting itself all the time
$callback_url="https://www.mydomain.com/path/to/app/callback-foursquare.php";
$client_id="xxx";
$client_secret="yyy";
$authorize_url="https://foursquare.com/oauth2/authorize?client_id={$client_id}&response_type=code&redirect_uri={$callback_url}";
$access_token_url="https://foursquare.com/oauth2/access_token?post_checkins=post_checkins&client_id={$client_id}&client_secret={$client_secret}&grant_type=authorization_code&redirect_uri={$callback_url}&code=";
?>
checkin-foursquare.php:
<?php
include_once 'inc/locations.php'; // this is where my location info is stored
include_once 'inc/fs_conn.php'; // these are the keys/urls
session_start();
$_SESSION["loc_id"] = $_GET["loc_id"];
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://foursquare.com/oauth2/authenticate?client_id=" . $client_id . "&redirect_uri=" . urlencode($authorize_url) . "&display=touch&response_type=code";
echo("<script> top.location.href='" . $dialog_url . "'</script>");
} else {
if($_GET['post_checkins']=='post_checkins')
{
$url = 'https://api.foursquare.com/v2/checkins/add';
$fields = array(
'venueId'=> $venue_id,
'venue'=> $venue_name,
'shout'=> $shout,
'broadcast'=>'public',
'll'=> $loc_lat . "," . $loc_long,
'oauth_token'=> $_SESSION['access_token']
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
header('Location: word-foursquare.php?loc_id=' . $_SESSION["$loc_id"] ); // this displays the secret word
exit;
}
}
?>
callback-foursquare.php:
<?php // this is what gets redirected from Foursquare and is listed in the "callback" field
include('inc/fs_conn.php'); // keys/urls again
$access_token_url=$access_token_url.$_GET['code'];
$access_token=json_decode(file_get_contents("{$access_token_url}"),true);
$_SESSION['access_token']=$access_token['access_token'];
header('Location: checkin-foursquare.php?loc_id=' . $_SESSION["loc_id"] . '&post_checkins=post_checkins');
exit;
?>
So basically it goes index.php -> checkin-foursquare.php -> foursquare.com -> callback-foursquare.php -> back to checkin-foursquare.php to actually do the checkin -> word-foursquare.php
Does this look correct?
If I go to 'https://www.mydomain.com/path/to/app/checkin-foursquare.php?loc_id=SOME-CITY-HERE' it correctly loads the login page. When I log in, it correctly brings up the "Connect your foursquare account with:" screen. However, once I get to this point, clicking the "Allow" button points me back to foursquare-checkin.php and then brings up the same "Connect your foursquare account with:" screen up, over and over. I feel like I am missing some token or something, like Foursquare isn't authorizing correctly (like I'm not supplying it with the correct token?), but I have no clue what's wrong. :(
I do notice that at the end of the looped URL there has been 'error=redirect_uri_mismatch' appended. However the callback URL in my Foursquare settings is the same as the $callback_url in fs_conn.php... so I'm not sure what's wrong with the redirect URI..?
I tried looking at this but it didn't help much, it looks like what I am doing but with the code split up differently (e.g. I don't need popup windows): Connecting with FourSquare API V2 using PHP
I do know that I only have half of the CSRF protection in there, but I'm not sure how to properly implement it with Foursquare. Is this what's causing me to get stuck in a loop? :(
Anyways, I'm sorry this is so long, and I'm forever grateful to anyone who has read this far. I've read so many pages here on SO that's it's all starting to blur together. I've been using this site for years and this is the first time I've never been able to figure something out on my own. Failure. :(

While not officially supported, there are a number of community contributed libraries for the foursquare API. If you're using PHP to access the API, you should consider using one of the listed PHP libraries: https://developer.foursquare.com/resources/libraries

Related

search Instagram with multiple hashtags - API

i have read that it is not possible by Instagram API , but the example site hashtagpirate.com does it, and there is an app on iOS as well, so there must be a way
i am developing a website with PHP and Instagram API, and have a plan for an App later on, can anyone point me to documentation on Instagram API which supports multiple hashtags fetching , as current API documentation ( below example code) doesn't seem to fetch more than one tag at a time
<?php
require 'Instagram.php';
$instagram = new Instagram('id');
$tag = 'selfie';
$media = $instagram->getTagMedia($tag);
echo "<ul id=\"photos\">";
foreach ($media->data as $data) {
echo "<li><img src=\"{$data->images->thumbnail->url}\"></li>";
}
echo "</ul>";
?>
i cant send more than one tag (selfie), and if i send two tags , the results are separate
thank you
You will need to do a separate search for each tag and then combine them yourself before presenting them to your users.
Due to the construction of instagrams database, you aren`t able to search instagram for multiple hashtags directly.
You have to use some third party sites like hashtagpirate.com or the free alternative vanadium

Is there a way to recognize google bots with the php?

I just made a website for an alcoholic drink. They need to have the age verification on all links. It's a single page website and I use backbone routing system. I've created the check with the SESSION object, so I am loading the intro view (age verification view) if the SESSION object is unset. This is all working as expected, but the problems are google bots. When they are trying to crawl my pages the app is always loading the intro (age verification) view. Here is a link for the website , but I think it won't be very useful, because I guess that this is more a logical then a technical question...
So..my question is how to redirect only visitors and to let google bots see the actual content of the page? Should I use cookies or there is a way to achieve this with the php?
Yes. Something like
If ($_SERVER['HTTP_USER_AGENT'] == "Googlebot") {
$_SESSION['ageverified'] = true;
// do more
}
Should work.
See here for all the exact user-agent names and what they crawl.
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=1061943

How to get access token for access Pinterest Api

I have Googled and searched on stackoverflow but could not find the answer.
I am writing an app, and this needs access to the Pinterest API.
This is my github repo: https://github.com/kellan/pinterest.api.php
$p = new Pinterest_API();
$p->fetch_access_token($client_id, $client_secret, $username, $password);
$resp = $p->some_api_call($args);
But i dont know where to find $client_id and $client_secret?
Go here, click Generate, and get an access token: https://developers.pinterest.com/tools/access_token/
Example: get statuses using: https://api.pinterest.com/v1/me/pins/?access_token=TOKEN&fields=id,creator,note&limit=2
See docs for extra parameters and requests: https://developers.pinterest.com/docs/api/overview/
As far as I'm aware, the Pinterest API has been taken down. I even got a take-down notice on my Pinterest Chrome extension.
Yep, Pinterest API has been taken down. All my apps were affected as well.
This v1 api link now only shows hyphen, dash on its count
http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=http://facebook.com
We can only wait till its back. I bookmarked your question and will try to update you when its back.

How to know which facebook friend clicked my stream story?

Is there any way to know which facebook friend clicked on story published from my facebook app? Is possible with/without authorization?
The only thing I can really suggest trying is REFERERS. PHP have a referer 'function' which can return the website that the user last came from.
<?php echo $_SERVER['HTTP_REFERER']; ?>
Obviously the above is a VERY basic example. But once you have done that you can loop through and see where the user came from and then add the data into a database-table or whatever you want to do with it.
This is not possible due to privacy issues. Facebook doesn't give any kind of info about what specific user viewed your profile, clicked your link, or anything of that nature.

Creating an IM bot

I am trying to create an IM bot and I haven't been able to find the necessary resources.
UPDATE
There was an issue with Imified making gtalk bots not appear online (and not responding), it works now so I'm closing this.
This tutorial does work.
Original question not deleted for reference purposes
First, I did find a great tutorial on How to Write Your Own IM Bot, but it uses the IMified platform which looks dead (last blog post in septembre 2008, no feedback on their help forum, ...).
I did manage to create a beta bot using their service but as I can see in their help forum, it will never be online.
So, any one managed to do it?
Notes
I'm looking for something that would be:
Free
Works with PHP* or some free hosting solution (like IMified but that works)
Works for Google Talk (I don't really care about the other)
Of course, do post answers about any solution that doesn't fit these criteria, it might help.
*I have a Linux hosting plan on GoDaddy
Google Talk uses jabber, where the protocol is called XMPP. A quick google search for "xmpp bot php" led me here. This should be enough for a start ?
Taken from the tutorial in case it ever disappears:
Step 1: Go to imified.com and request an invite. You should
also give your bot a decent name because you can have just one bot per
email address.
Step 2: An email with a secret key should arrive in your Inbox the
next minute. Copy that key to the clipboard and go here to redeem that
key.
Step 3: Now it's time to create a bot which is actually a simple
script that resides on your public web server. It could be in PHP,
Perl, Python or any other language. More here.
This is the source of the PHP script I wrote for the labnol IM bot -
pretty self explanatory - it reads your message, gets the relevant
data from Google Suggest and echoes it back to the IM window.
<?php // Get all the related keywords from Google Suggest
$u = "http://google.com/complete/search?output=toolbar"; $u = $u . "&q=" . $_REQUEST['msg'];
// Using the curl library since dreamhost doesn't allow fopen
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $u);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = simplexml_load_string(curl_exec($ch));
curl_close($ch);
// Parse the keywords and echo them out to the IM window
$result = $xml->xpath('//#data');
while (list($key, $value) = each($result))
{
echo $value ."<br>";
}
?>
Step 4: Once your script is ready, put
it somewhere on your web server and copy the full URI to the
clipboard.
Now login to your imified account, paste the script URL and add that
im bot your friends list. That's it.