| Subcribe via RSS

Make Twitter Updates with PHP and cURL

June 18th, 2010 | No Comments | Posted in API, PHP, Programming

I’m sure I’ve mentioned sometime before that I’m a big fan of Twitter. I think Twitter has done a great job with their API, and the documentation for their API. They’ve made it fairly simple for developers to create Twitter based applications without jumping through a lot of hoops.

Well below is a bit of code I’ve used in the past to make status updates to Twitter. If your familiar with cURL then you’ll see that its pretty straight forward. The end result examines the HTTP code to determine if the status update was successful or failed you can comment this part out if you wish.

But before you go plowing away with the code I think it would be a good idea if you make yourself familiar with their documentation. They have a few rules that could save you some heartache down the road.

== Twitter Documentation ==
http://apiwiki.twitter.com/Twitter-API-Documentation

== PHP Code To Post Twitter Status Updates ==

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?PHP

/* Post Twitter Status Update using PHP & cURL */

function postToTwitter($username,$password,$message){
 
   $username = $username;
   $password = $password;
   $twitterHost = "http://twitter.com/statuses/update.xml";
   $yourStatus = $message;
   $curl;
   
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
   curl_setopt($curl, CURLOPT_HEADER, false);
   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
   curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
   curl_setopt($curl, CURLOPT_POSTFIELDS, "status=". urlencode(stripslashes(urldecode($yourStatus))));
   curl_setopt($curl, CURLOPT_URL, $twitterHost);
   
   $result = curl_exec($curl);
   $resultArray = curl_getinfo($curl);
   
   if ($resultArray['http_code'] == 200) {
   
   $twitterPostStatus = "Success";
   
   } else {
   
   $twitterPostStatus = "Failed";
   
   }
   curl_close($curl);
   
 return $twitterPostStatus;  
}

$username = 'username_here';
$password = 'password_here';
$message = "Working with the Twitter API";

$result = postToTwitter($username,$password,$message);

print_r($result);
?>
Tags: , ,

Frinly WordPress Widget

June 17th, 2010 | No Comments | Posted in PHP, Programming, wordpress

Just a really quick update. The Frinly WordPress Widget was accepted into the WordPress Plugin directory a couple of days ago. It is now available there also.
http://wordpress.org/extend/plugins/frinly-photo-sharing-widget/
http://frin.ly/recommend/wordpress/
Later,
Joe

Tags:

Fixed Broken Links

June 12th, 2010 | No Comments | Posted in PHP, Programming

I just noticed I had some broken links on my PHP Scripts page. I repaired the links so the downloads should be back to normal.
I have to say I looked over the code that was used to make this scripts and a lot of it is old. I’m leaving it in place hoping that it can still in some way be helpful.
Later,
Joe

- – UPDATED –
I included two scripts that I had on the old site that somehow was forgotten when I made the move.

Tags: , , ,

Twitter Oauth and Amazon A3

June 7th, 2010 | No Comments | Posted in Programming, wordpress

After about two weeks I’m back. Things took longer then what I expected but I did get a lot accomplished. I totally re-vamped my image hosting site, from a code perspective. Users are now required to have a twitter account to use Frinly. I’m using Twitter Oauth for log in authentication. I also added Amazon A3 service so now all of the images are hosted on Amazon’s servers. I’ve Built a Upload and Post and Post only API so that users can use 3rd party applications to post images. I’ve changed the way incoming email is answered and dumped the script and cron job that checked a designated pop3 account. And last, but not least I upgraded the Frinly WordPress Widget so now you don’t have to hack the code to configure it to work. Now configurations are made through the options interface.

I think I kicked some ass actually. There where a whole bunch of tutorials I had to read to get this done. Two weeks ago I had no idea how Amazons cloud storage worked. Now I’m scratching my head wondering why in the heck haven’t I been using this all along. It’s awesome!

I’m not 100% finished yet. I have a few more features that I would like to add but I’m going to hold off for a couple of weeks before I start on them. I really want to work on this other project I’ve been thinking about for sometime now. I plan to post updates when I can but to be honest I know how I am when It comes to programming. It consumes me.

Overall the best part of buckling down and learning how these services work is the knowledge. I now have to knowledge to build bigger and better applications. So basically you have to look at the time spent as an investment.

Later,

Joe

Tags: ,

Twitter IPhone App – Custom API URL

May 21st, 2010 | No Comments | Posted in API, Programming

Change of plans. I decided to take an opportunity I came across yesterday.Custom API URL - Twitter IPhone App
Let me explain. I subscribe to Tech Crunch via twitter, that’s my way of keeping up with who’s, who’s and the what’s going on in the tech world. Well I saw a post they made yesterday about a new twitter IPhone application that was coming out or maybe it was just being renamed, I can’t remember but you get the idea, right?  So I thought why not give it a try. So I went to the Itunes App store via my IPhone and  downloaded the app. I played around with it for a while and quickly became very happy with the functionality. It had a butt load of options and was totally ad free. For the longest I had been using Echofon which wasn’t.
Any who, one of the features I played around with while testing was the photo posting. Photo posting is probably one of the most important feature for me. I figure I can text my posts in if needed.

So to test this feature out I added a test twitter account to the app and posted a random photo from my IPhone. The photo showed up immediately which is great, but when I took a closer look I realized it posted the image to Yfrog. WTF, I was kind of irritated for a little while and wonder why in the heck would they use that site, I hate that site. So I went back to the app to see if there where other options I could select from that would allow me to change this out. Echofon has that feature, so I assumed they would also. Now hold your hat on what I’m about to tell you next, it’s a shocker. Not only did they have several options to choose from, they also had an option that would allow you to add your own custom API URL. Yea that’s music to my ears. First off I love using API’s and secondly I just so happen to have a image hosting site that posts to Twitter and Facebook. So that was it, I knew my night was on lock. I took a pause for a few minutes and then went straight to Burger King and grabbed a couple of those $1.00 double cheeseburgers, came back to the house and started coding my ass off. I think I went to sleep around 4 am, but had to get back up by 9:00 am, I had some shares of stock that I was trying to dump before the market bottomed out.

So to make a long story short I completed building the API for my site sometime around 5 p.m. today. It took longer than what I expected because the market went running today. If you’re curious I took home an extra 315 bucks today. But I have everything working now. You can now post images to your Frin.ly account from Twitter’s IPhone app. I’m not advertising the API right now because I want to take sometime to revamp the site before I start to let people use it. I was looking at some of the code and some of it didn’t make since to me, and I was the person who wrote it. Go figure.

Anyway I said all of this to say that I’m off track right now and things will probably be pushed back another week or so I think. But I’ll keep you posted.
Later,
Joe

Tags: , ,

Geolocation by IP Address with PHP

January 5th, 2010 | No Comments | Posted in API, PHP, Resource

Something kind of interesting happened today. I was going through my log files and noticed a query for “joe Tinsley woodland park” the query originated from “Medford, Massachusetts”. Woodland Park was an elementary school located on an air force base in South Carolina that I attended when I was a kid. I take it that someone from my past is trying to locate me. That’s pretty cool. The crazy part is I just noticed that I don’t have anyway for anyone to contact me via my website… Ha! I make the craziest moves sometimes.
Well I’ve mentioned all of this to say If you’re looking for a way to pull Geolocation Data from a single IP address try IPpages.com’s APIs. I’ve been using them for some time now and the service is pretty good. It does require some programming knowledge to the extract the data from the XML results.
Please let me know if I can help with any programming questions (PHP only!).

Tags: , ,

Google XML Sitemap: Export Title, Description and Keywords to Excel

December 8th, 2009 | No Comments | Posted in Google, PHP, Programming, SEO

Google XML Sitemap: Download the Title, Description & Keywords tags from your sites webpage via your Google XML sitemap and then export the data into a excel spreadsheet. I’m not totally sure what to call this tool yet. I started out creating something else and took a totally different direction. That’s not to say this is not a useful tool. Basically if you’ve ever been in a situation and wonder how many URL’s are included in a Google XML sitemap, then this application will help you. Or if you’ve ever been in a pickle and wondered how well my Titles, Descriptions, or Keywords Tags are optimized, then this application will help yuo also. Once you submit your Google XML sitemap the application will download all of the URL’s included in your XML Sitemap and then one URL at a time goes out and fetches the Title and Meta Information. It then runs the character count from this data against what is deemed by Yahoo as being a well formatted Title and Meta Tag by YSSP standards. Title 70 characters in length, Description 170 characters in length, and 12 Keywords. I took a look at the Google Webmaster rule set also and added in some padding.
So for example the application will color the character count number Green if the Title falls in-between 60 and 70 characters. Then Red if the count is over 70 characters and Purple if it’s under 60 characters. This color theme is used also for the Description and the Keywords.

The complete thresholds includes.
Title: >=60 <=70 Good; > 70 Red; < 60 Purple
Description: >=150 <=170 Good; > 170 Red; < 150 Purple
Keywords:   >=10 <=12 Good; > 12 Red; < 10 Purple

Google Sitemap Tool
Creating and submitting Sitemaps

Tags: , ,

Reverse IP Lookup, FREE PHP Tool

November 17th, 2009 | No Comments | Posted in PHP, Programming

Reverse IP Lookup, Search for domains hosted on a single IP address

As some of you have probably already noticed I’ve added a new link/script/tool to the site. I have a bunch of these one offs scripts scattered around the internet. I’m currently trying to rope them all into one location.

But basically this tool will look ups and reports what other domains are hosted on a particular server. It’s actually fairly simple and works off of an operator that most are not aware of.

How it works. Simply just add a domain with the dubb and the tool will do the rest. I capped it off at 30 results. So even if there are thousands the tool will only report back 30 other domains.

Tags: ,

Google Favicon API, PHP Code

November 10th, 2009 | No Comments | Posted in API, Google, PHP, Programming

I ran into something very, very interesting today. Google Favicon API
(A Favorite Icon API)
. It’s an API that allows you to pull websites Favicons, plus the API dynamically converts the image into a PNG format. This actually comes at a great time because I was just thinking the other day that since I have the option to add offsite URL’s to my site now. Would’nt it would be supa cool if I could also included their Favicon? To beak it down if you look into my site’s right side navigation you will see the “Links” category. Well I thought it would be nice, I mean supa cool if I had a script that could automatically include the corresponding sites Favicons.  And BAM! Thanks Google Favicon API. I wrapped this APIs up with some cURL and a little PHP and now I have a working PHP function. I don’t know much about the Google Favicon API but it looks like it’s been around for about a year. So it’s a good chance that this API could suddenly up and move or disappear all togehter. Basically what I’m saying is I don’t know how long the good times will last. So in my opinion I suggest you consider the use of this script temporary until you can get the time to build a much reliable one yourself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?PHP
function getFavicon($var){
$filName=substr($var,0,-4);
$fp = fopen ('folder/'.$filName.'.png', 'w+');
$ch = curl_init('http://www.google.com/s2/favicons?domain='.$var);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);

}

$var='techcrunch.com';
getFavicon($var);
?>

Tags: , , ,

RSS Auto Discovery, Do it now

November 10th, 2009 | No Comments | Posted in Programming, XML

Added a dynamic RSS Auto discovery feature to my site today. Yea nothing earth shattering but I thought it was still pretty cool. Then for shsss and giggles I started surfing the web to see who didn’t have one. I was shocked to see that there’s a lot of big named website not taking advantage of this small addition.

For example

  • Mint.com, http://www.mint.com/blog/ – Mint offers a RSS Feed but not a Auto Discovery feature hosted off of the home page. This option is only available to you when you visit the Feedburner hosted page.
  • My.barackobama.com, http://my.barackobama.com/page/content/hqblog -  Basically the same thing as Mint.com. You only see this option on the Feedburner hosted page. And not off the home page. (I’m not even going to get into why they are not using the branded feedburner solution.)
  • Whitehouse.gov, http://www.whitehouse.gov/ – They DO offer a RSS Feed and a RSS Auto Discovery option on the home page. Good deal!

This is actually pretty interesting because it’s so simply to implement and in doing so will make things easier for your readers. Part of the game plan is to get people involved, why not make it easier from then to keep up.

So anyway here some code and some links to reference if you want to add this feature to your site.

1
2
3
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.josephtinsley.com/feed/rss.xml">

<link rel="alternate" type="application/rss+xml" title="ADD SITE TITLE HERE" href="ADD RSS FEED URL HERE"/>

Tags: ,