How to use Google+ APIs from ASP.NET - samples and source code

Are you trying to integrate Google+ with your .NET applications? Google+ provides some APIs, but the output is in JSON format. Download the .NET client library for Google+ APIs and see our examples to find out how to use them.

Google released Google+ platform last month and announced some APIs few days ago to integrate Google+ with custom applications. The initial version of Google+ APIs can be used to retrieve public data from Google+ system. Future version of Google+ APIs will support more advanced operations like posting to your Google+ profile or Google+ page, retrieving private information etc.

Today I was trying to integrate Google+ with our websites to retrieve and show the list of our pages shared in Google+. I quickly realized the data retrieved using the Google+ APIs are not strongly typed as I would expect in .NET. Instead, Google+ APIs return data in JSON format, which is a structured form of data, but not strongly typed like .NET types.

I tried couple of Google+ APIs. After couple of trial and error, I was able to call some Google+ APIs, using the WebRequest class in .NET.

Here is the code I used to call Google+ API:

string requestString = "" + _profileId + "?key=" + _apiKey;
WebRequest objWebRequest = WebRequest.Create(requestString);
WebResponse objWebResponse = objWebRequest.GetResponse();

Stream objWebStream = objWebResponse.GetResponseStream();

using (StreamReader objStreamReader = new StreamReader(objWebStream))
string result = objStreamReader.ReadToEnd();

return result;

In the above code, _profileId represents a valid Google+ profile. It does not need to be any valid profile id. This API returns only public information from any profile and so no authentication is required to call this. However, you need to pass an API Key before you can call the Google+ APIs. That is what I used in the variable _apiKey. You can get a Google+ API Key from here.

The above code returns some text data in JSON format, which is structured data.

We need to convert the data in to valid .NET types. The JavaScriptSerializer class comes in handy here. We can use this class to convert the JSON data structure to corresponding C# or VB.NET class.


JavaScriptSerializer js = new JavaScriptSerializer();
string requestString = ""
+ _profileId + "?key=" + _apiKey;
string result = GetWebData(requestString);
GPlusPerson activity = js.Deserialize(result);

GPlusActivity is a custom class I created that matches its properties with the keys in the JSON structured returned by the Google+ API. Each property in the class must match with the key names in the data structure returned by the API. The JavaScriptSerializer DeSerialize call will convert the data structure in to corresponding .NET object.

In my example, the above API call returns the following JSON data:

"kind": "plus#person",
"id": "102428175534077457150",
"displayName": "Tony John",
"tagline": "Microsoft MVP, Founder of",
"gender": "male",
"aboutMe": "",
"url": "",
"image": { "url": "
"urls": [ { "value": "" },
{ "value": "" },
{ "value": "" } ],
"organizations": [ { "name": "LoneStar Informatics LLP",
"title": "Owner", "type": "work" } ],
"placesLived": [ { "value": "Bangalore, India" } ]

Now, to match the JSON structure, I have defined the .NET class like this:

public class GPlusPerson
public string kind { get; set; }
public string id { get; set; }
public string displayName { get; set; }
public string tagline { get; set; }
public string birthday { get; set; }
public string gender { get; set; }
public string aboutMe { get; set; }
public string url { get; set; }
public GImage image { get; set; }
public Url[] urls { get; set; }
public Organization[] organizations { get; set; }
public PlaceLived[] placesLived { get; set; }

You can see that each of the key in the JSON structure has a corresponding property in the .NET class. the DeSerialize method of the JavaScriptSerializer class will map the JSON key-value pair to the corresponding .NET property.

You may notice that some of the items in JSON structure is an array of data by itself. Examples: Image, Organizations, PlacesLived. I have defined each of them as separate types (classes).

You can download the full set of classes to map each of the JSON structure for all the Google+ APIs released in October 2011 (version 1). I have included some samples and basic documentation on how to call each of the Google+ APIs.


  • GooglePlusLib.NET client library for .NET with samples (
  • More articles: Google+ APIs Google+


    Guest Author: Suresh17 Mar 2013

    Great ! Thank you.

    Author: ketan Italiya29 Aug 2013 Member Level: Gold   Points : 0

    Thanks,tony this is most useful.for me.thanks

    Guest Author: Sunitha19 Aug 2014


    Please let me know the way to post to Google+ using .Net server side coding.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: