TECKpert’s Tips: Using Google Base with .NET for Real Estate

November 27, 2009 / By: Adrian

Adding listings to Google Base Real Estate is simple and completely free. Today I’ll show how to, using the Google Base .NET library, add listings to Google Base and then search for those listings. The library can be downloaded at http://code.google.com/apis/gdata/client-cs.html.

First import the following classes from the Google Base Client library.

using Google.GData.Client;

using Google.GData.GoogleBase;

To insert items, you need to be authenticated. Specify your Google Base account name and password to GBaseService as follows. You can use your Gmail account but you have to first sign into Google Base to activate the account.

GBaseService service = new GBaseService("Application Name", developerKey);

service.setUserCredentials("username", "password"); 

The next step is to create the GBaseEntry you would like to insert.

GBaseEntry entry = new GBaseEntry();

entry.Title.Text = "My Title";

entry.Content.Content = description;

It is important to set the ItemType to “Housing”.

entry.GBaseAttributes.ItemType = "Housing"; 

Now set the other attributes. To see a list of all the Google Base attributes go to http://base.google.com/support/bin/answer.py?hl=en&answer=78170.

FloatUnit unit = new FloatUnit(price, "usd");

entry.GBaseAttributes.Price = unit;

entry.GBaseAttributes.AddTextAttribute("feature", feature);

entry.GBaseAttributes.AddImageLink(imgLink);

entry.GBaseAttributes.AddTextAttribute("property_type", propertyType);

entry.GBaseAttributes.AddTextAttribute("listing_type", listType);

entry.GBaseAttributes.AddTextAttribute("listing_status", listStatus);

FloatUnit sunit = new FloatUnit(sqft, "square ft.");

entry.GBaseAttributes.AddFloatUnitAttribute("square_feet", sunit);

entry.GBaseAttributes.AddFloatAttribute("bathrooms", baths);

entry.GBaseAttributes.AddIntAttribute("bedrooms", beds);

entry.GBaseAttributes.Location = "Address, City, State xxxxx USA ";

entry.GBaseAttributes.AddTextAttribute("mls_listing_id", listingID);

entry.GBaseAttributes.AddTextAttribute("broker", listBroker);

entry.GBaseAttributes.AddTextAttribute("agent", listAgent); 

Finally, insert this GBaseEntry object into the Items feed.

 GBaseEntry ent = service.Insert(GBaseUriFactory.Default.ItemsFeedUri, entry); 

The method service.Insert returns the item you just inserted. The Google Base server assigns pre-computed attributes for your entry such as the creation date and time, the author, and most importantly, the identifier (or URL) of the new entry. The entry may take a few hours to publish so it may not be searchable immediately.

Now you can search for your listings on Google Base by connecting to a snippets feed URL and then interpreting the resulting atom feed. This can be done programmatically by creating a GBaseService object and executing a query on it.

GBaseService service = new GBaseService("Application Name", developerKey);

GBaseQuery query = new GBaseQuery(GBaseUriFactory.Default.SnippetsFeedUri); 

The following query will get single family homes for sale within a 5 mile radius of San Francisco CA.

query.GoogleBaseQuery = @"[item type:housing] [listing type:for sale] [property_type:single] [location:@""San Francisco, CA, USA"" + 5mi]";

You can also set the sort by and order, number of results, and search start index.

query.NumberToRetrieve = 20;

query.StartIndex = 0;

query.AscendingOrder = true;

query.OrderBy = "price(float USD)";

Lastly, execute the query and save the atom feed into a readable xml format. This can be parsed and displayed on a web page.

XmlTextReader reader = new XmlTextReader(query.Uri.AbsoluteUri);

XmlDocument doc = new XmlDocument();

doc.Load(reader); 

Pretty simple right? Now you can have your listings searchable on Google along with your website.



 
 

Need Help?

Give us a call

786 393-5826

Talk with one of our professionals and start working with TECKpert today.

Speak with us

Over 20 national and regional awards

2018

Communicator Award - General Manufacturing - Marmol

Communicator Award - General Lifestyle - Marmol

2017

South Florida Business Journal - Top Web Design and Development Company - Ranked #2

Daily Business Review - Best Of Internet Marketing - Ranked #3

Daily Business Review - Best Of Web Design - Ranked #3

Davey Awards - Silver Award - Zilbert

2016

South Florida Business Journal - Top Web Design and Development Company - Ranked #2

Daily Business Review - Best Of Internet Marketing - Ranked #2

Daily Business Review - Best Of Internet Marketing - Ranked #3

Davey Awards - Silver Award - CorkageFee (website)

2015

Daily Business Review - Best Of Internet Marketing - Ranked #3

Daily Business Review - Best Of Web Design - Ranked #3

South Florida Business Journal - Top Web Design and Development Company - Ranked #5

2014

W3 Awards - Silver Award - CorkageFee (Mobile Application)

Communicator Awards - Award of Distinction - ERP Maestro

Communicator Awards - Award of Distinction - AADS

Communicator Awards - Award of Excellence - TECKpert

Davey Awards - Silver Award - CorkageFee (Mobile Application)

W3 Awards - Silver Award - Hubdin

2013

Davey Awards - Silver Award - Midtown Women's Center

Davey Awards - Silver Award - MSG Law

W3 Awards - Silver Award - Leon Cosgrove

Communicator Awards - Award of Distinction - 400SunnyIsles.com

Communicator Awards - Award of Distinction - Esolist.com

Communicator Awards - Award of Distinction - CSK Mobile

2012

Interactive Media Awards - Winner for TECKpert.com

Daily Business Review - Best Of Internet Marketing and Web Design