Creating an IM bot - instant-messaging

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.

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

Google Spreadsheet API: Post request fails

I have a Google spreadsheet published to the web, and I'm trying to read and write list-based feeds. I have not authenticated.
I can read data using a GET request just fine.
curl https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDsadfwerF4RE0M/1/public/full
However, all my post requests to write data come back with an error
curl --data '' https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDlN3mMaBfF4RE0M/1/public/full
curl --data '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended"><gsx:id>1</gsx:id><gsx:status>1</gsx:status><gsx:user_email>1</gsx:user_email><gsx:url domain>1</gsx:url domain><gsx:highlighted_text>1</gsx:highlighted_text><gsx:complete_text comments>1</gsx:complete_text comments><gsx:created_date>1</gsx:created_date><gsx:updated_date>1</gsx:updated_date><gsx:created_by>1</gsx:created_by><gsx:updated_by>1</gsx:updated_by></entry>' https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDlN3mMaBfF4RE0M/1/public/full
The error I'm getting is: "Sorry, the file you have requested does not exist. Please check the address and try again."
Do POST request require authentication? I can't find anything in the docs that say so.
Any help would be appreciated. Thanks.
Two things:
I think you need to use the private feed (.../private/full), not the public one (.../public/full) like you're using now. More on the private-versus-public distinction is in the API docs.
You will need an Authorization header. (That process gets pretty complicated, but there's a lot of good info here. Remember to select the appropriate scopes.)
Both are mentioned in the example about adding a list row in the Sheets API docs. (I'd link directly, but I don't have enough rep to add more than two links. Just search for "Adding a list row".)

How to check Bitcoin address balance from my application?

How do I check a balance of a Bitcoin address (any, not necessarily mine), let's say in a Java application (or any other language)?
I need a functionality like the one on blockchain.info or biteasy.com but I don't want to use their API. Bitcoin is open source, so I thought maybe it won't be so difficult to get the data myself?
For now there is no simple way to get balance of a address that not in the wallet with bitcoin core. Maybe this function is under developing.
To get a address's balance, you need to compute the utxos on the address from the whole block chain. (I guess fornow there maybe no record of balance on each address, so you've to calculate it form the whole block chain)
You said in your question, you didn't want to use third site's API
(For example https://api.blockcypher.com/v1/btc/main/addrs/38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa).
You can run a bitcoin browser in you device, for example bitcoin explorer
Use blockexplorer.com model and piggy back off their server or run your own using open source version at github.com/lirazsiri/blockexplorer
It is not necessary to use web wallets to create addresses. You can install your own bitcoin server/daemon and act like your own bank.
This is the place to start if you want to know how to do it (https://en.bitcoin.it/wiki/Main_Page).
Bitcoin can be queried using JSON RPC methods. So if you are running a bitcoin daemon locally you can just query them. The documentation for the same is located at
Running Bitcoin - https://en.bitcoin.it/wiki/Running_Bitcoin
API Reference - https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)
API Call List - https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
Hope this helps.
You can use JSON-RPC method. bitcoind widely supports JSON-RPC calls. So just go to the official website of bitcoin and find all of the methods.
Here is an example in PHP. Just include the jsonClient.php file
<\?php
require_once jsonRPCClient.php'; <br />
$bitcoin = 'https://' . $rpcusername . ':' . $rpcpassword .
'#' . $rpcip . ':' . $rpcport . '/'; <br />
print_r($bitcoin->getnewaddress());
?>

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.

Foursquare API Checkin

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