Posts Tagged ‘api’

Using the Salesforce API

Monday, December 4th, 2006

Just posted my Using the Saleforce API article on the O’Reilly Network:

In this article I’m going to turn a blog into a Salesforce lead generator by integrating the blog comments with Salesforce Leads using the Salesforce API, SOQL (a Salesforce-specific, SQL-like query language), and some Salesforce object customization.

If you hear the phrase “lead generation” and picture a car salesman, then you should probably step back and think about what you do when someone posts a comment to your blog. Do you try to find their blog? Google them? Go as far as emailing them? If you comment on my blog, you can be assured that I’m going to email you back.

Lead generation and tracking is a big part of any sales process and a major concept inside the Salesforce CRM. Many businesses are adding blogs to their sales and marketing activities and will want to integrate these into their existing sales process.

Introduction to Salesforce AppExchange

Monday, November 13th, 2006

I went to a Salesforce conference recently to investigate Salesforce as a platform for building applications for the business web. I liked what I saw. The tools they are building for developers fit very much with the trend toward smaller development companies (i.e. one or two people) who can focus completely on the product because the infrastructure for running the rest of the company already exists.

Today O’Reilly posted part one of my three part series on building for Salesforce AppExchange, An Introduction to Salesforce.com’s AppExchange.

YouTube API How-To

Wednesday, November 8th, 2006

What is it

The YouTube API lets you search for videos and display them on your site. For example, I use the API to pull videos tagged dance and display them on Rate My Dance Moves. The YouTube API is currently the 10th most popular API on ProgrammableWeb with 46 mashups.

To get started you need to sign up for a developer account. That will give you the developer id required to use the API.

Using the API

The major API methods are for retrieving lists of videos, which you can do by tag, user, user favorites, and featured. The information returned from the list methods is usually enough to display a video on your site. All you have to do is plug the video id into the web snippit below.


<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/ID&autoplay=1″>
</param>
<embed src=”http://www.youtube.com/v/ID&autoplay=1″
type=”application/x-shockwave-flash” width=”425″ height=”350″></embed>
</object>

Most of the information you need is in the video list methods. However, if you want a list of comments or channels for the video you’ll need to call the get_details method.

One complaint I had with list_by_tag is that the results come back ordered by relevance rather than recency. That means if you want to build a self-updating site you need to either regularly crawl the entire result set (results are paged) or sit on one of the RSS Feeds.

API Wrappers

There are good libraries for using the YouTube API with Perl, Ruby, and .NET. If you’re using another language, say Java, PHP or Python, you’ll have to write some code yourself. I’ve included links to example PHP and Python code and listed an example Ruby program that you can use as a template for whatever language you’re writing in.

There’s two competing Perl modules, but Hironori Yoshida’s WebService::YouTube and WebService::Youtube::Feeds seem best based on the recent development activity and strength of documentation. His is the only wrapper which includes support for the feeds, nice since the feeds have functionality thats not in the API (namely list by recency).

Shane Vitarana released a YouTube Ruby Gem after I’d built RateMyDanceMoves. Too bad, since it seems like the most polished of all the wrappers.

Eamonn Flynn has a .NET wrapper for the YouTube API.

There doesn’t seem to be a packaged PHP library but these two tutorials from waxjelly should be enough to get you started.
Simple PHP Script Using the YouTube API with Pagination
A More Complex PHP Script Using the YouTube API with Pagination.

ThinkHole labs has some example YouTube API code for Python users. Apparently using the API can be as simple as passing a dictionary to YouTube’s XML-RPC interface.

Code Example

I’d written my own code before the Ruby library came out. I want to show it here so you can see how simple writing your own code would be.


#!/usr/bin/env ruby
require 'open-uri'

tag = "dancing"
per_page = "100"
def_id = "YOUR_DEV_ID_HERE"
url = "http://www.youtube.com/api2_rest?" \
+ "method=youtube.videos.list_by_tag" \
+ "&tag=#{tag}&per_page=#{per_page}&dev_id=#{dev_id}&page=1"

open(url) do |f|
xml = f.read
end

doc = REXML::Document.new(xml)

elements = doc.root.get_elements("//video")
elements.each do |v|
puts v.get_elements("id").first.get_text.to_s
puts v.get_elements("title").first.get_text.to_s
puts v.get_elements("tags").first.get_text.to_s
puts v.get_elements("thumbnail_url").first.get_text.to_s
end

More Info

The Amazing YouTube Tools Collection has a long collection of YouTube tools, mashups, and plugins.

Quotes On Your Phone

Friday, September 29th, 2006

Make iheartquotes your Twitter friend and get quotes messaged to your phone every day at 10am, 3pm, and 8pm.

If you’re not ready for daily updates but find yourself alone with your cell phone jonesing for a quote you can also text iheartquotes to MOZES (66937).

This latest I Heart Quotes integration is a mashup of the I Heart Quotes API and the Twitter API. The Twitter API is new but there’s already been some cool uses, like update Twitter with your IChat status. I’m sure there will be more, because 1. Twitter is awesome, 2. the API is dead simple.

BTW, I Heart the quote that Biz dug up for his post about this on the Twitter blog.

Tribute to the Unix Fortune Program

Sunday, September 10th, 2006

Introducing I Heart Quotes.

Unix used to have a lot of personality. RedHat would let you go through the entire installation in the language of ‘Redneck.’
And every server had a program called ‘fortune’ that would greet you with some manner of quote, joke, epigram, or other pithy comment. Things like this gave personality to an otherwise pretty nerdy hobby.

At some point the source of those quotes, the fortune program, stopped showing up on servers. A combination of Linux trying to compete in the corporate world and my leaving college to also compete in the corporate world led to working on servers with less personality. The fortune program still exists, but just isn’t as prevalent. I think that’s sad.

So what’s a man to do? Build a web service on top of every fortune file I could find on the internet (if you know of any that I missed, please email me). Now I (you) can get your fortune regardless of what’s installed on the server.

(I also built a digg-style website and ratings for the data, but that’s really beside the point.)

Here’s what I put in my .bash_profile to get a fortune every time I login:

alias getfortune='wget --timeout=3 -O - -q'
alias fortune='getfortune http://www.iheartquotes.com/api/v1/random'
alias myfortune='getfortune http://www.iheartquotes.com/api/v1/random?source=joel_on_software+paul_graham+prog_style
myfortune

If you’re on a Mac you probably have curl installed instead of wget. If so use this line:

alias getfortune='curl -m 3'

There’s more options on the official API page, the most important is that you can choose which sources the API pulls from (make sure you include Comic Book Guy from the Simpsons: simpsons_cbg). The available sources are below.

From geek:

esr
humorix_misc
humorix_stories
joel_on_software
macintosh
math
mav_flame
osp_rules
paul_graham
prog_style
subversion

From general:

codehappy
fortune
liberty
literature
misc
murphy
oneliners
riddles
rkba
shlomif
shlomif_fav
stephen_wright

From pop:

calvin
forrestgump
friends
futurama
holygrail
powerpuff
simon_garfunkel
simpsons_cbg
simpsons_chalkboard
simpsons_homer
simpsons_ralph
south_park
starwars
xfiles

From religious:

bible
contentions
osho

From scifi:

cryptonomicon
discworld
dune
hitchhiker