嫩草视频 两个人的免费视频完整版 午夜视频 好大哥dgdg 骚虎视频 嫩草视频 嫩草视频 骚虎视频 影视大全免费追剧 两个人的免费视频完整版 影视大全 嫩草官网 啦啦啦免费观看视频6 影视大全高清版 野花在线观看免费视频 嫩草视频 骚虎视频入口 免费无限资源 好大哥dgdg 啦啦啦免费观看视频6 啦啦啦免费观看视频6 两个人的免费视频完整版 啦啦啦免费观看视频6 骚虎视频入口 影视大全 啦啦啦免费观看视频6 嫩草视频 野花在线观看免费视频 啦啦啦免费观看视频6 影视大全 影视大全 骚虎视频入口 影视大全免费追剧 24小时日本在线视频 嫩草官网 影视大全免费追剧

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 = "https://www.googleapis.com/plus/v1/people/" + _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.

Example:

JavaScriptSerializer js = new JavaScriptSerializer();
string requestString = "https://www.googleapis.com/plus/v1/people/"
+ _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 dotnetspider.com",
"gender": "male",
"aboutMe": "",
"url": "https://plus.google.com/102428175534077457150",
"image": { "url": "https://lh3.googleusercontent.com/-wDpbQaFJFKg/
AAAAAAAAAAI/AAAAAAAAAAA/ZQ8VOHPB1Is/photo.jpg?sz=50" },
"urls": [ { "value": "http://www.thoughtsfromgeeks.com/member/manjaly.aspx" },
{ "value": "http://www.indiastudychannel.com/member/manjaly.aspx" },
{ "value": "http://www.alabamabondage.com/member/manjaly.aspx" } ],
"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.


Attachments

  • GooglePlusLib.NET client library for .NET with samples (43365-25043-GooglePlusAPIHelp.zip)
  • More articles: Google+ APIs Google+

    Comments

    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

    Hi,

    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:
    Email:
    好大哥影视-好大哥视频-好大哥官网-好大哥电影 骚虎视频官方-房事视频免费看 四虎视频官方-女人本色高清视频 午夜视频官方-24小时日本在线视频 好大哥视频-好大哥dgdg 野花在线官方-影视大全 久草视频入口-嫩草视频官网 小草视频入口-两个人观看野花免费视频 嫩草视频入口-大片免费视频