Publish Google+ Stream on your site





Google+ is still very young - it’s only a month old, it is growing, gaining popularity, and it is mysterious like a square watermelon. In the sense that it is completely incomprehensible how the developer can use it.

At the moment, it is only known that the API will be released on the next Google I / O, i.e. You will need to wait another year. It is clear that right now, with such a “freshness” of the service, it is impossible to give up any stable API - you can now pick up your stream only through Google Takeout . There is no "official" way to pick up a stream programmatically.

But, as you know, there is nothing impossible for geeks in love with the new service, and people with a shovel in their hands have already dug enough “unofficial” enough to get the stream. For example, PlusFeedRussel'a Beattie allows you to pick up a user's stream in RSS format, but if you are control freak, then this solution is not for you. Therefore, we will take the stream ourselves.

And it’s quite possible to do it yourself - it is available at: https://plus.google.com/_/stream/getactivities/XXX/?sp=[1,2,,XXX>,null,null,null,null, “Social.google.com”, []] ,
where XXX is your plus-id (the one that is visible in the url line on plus.google.com/me or on any other user's page).

The data that plus returns at this address only needs to be slightly processed - remove the prefix added so that the pioneers do not pull Json away and remove traces of optimization.

The result is something like this:



From the academic point of view, the code that produces this is not of interest - it is a banal LINQ query wrapped in an ASP.NET MVC application, the result of which is rendered using jQuery templates.

The most difficult thing here is to figure out who in the original Json is who - it is a heap of arrays, and there are no field names for you!

For example, to pull geo location data, you have to do something like this:
GeoData = post[27].HasValues ?
	new
	{
		Name = post[27].Values().ElementAt(2).Value(),
		Address = post[27].Values().ElementAt(3).Value(),
		MapsUrl = post[27].Values().ElementAt(9) == null ?
		null :	post[27].Values().ElementAt(9).Value(),
		PlaceUrl = post[27].Values().ElementAt(10) == null ?
		null : 	post[27].Values().ElementAt(10).Value(),
		MapImage = post[27].Values().ElementAt(11) == null ?
		null :	 post[27].Values().ElementAt(11).Value()
	}
	: null,
...


For clarity, Google’s stream import is implemented using the Hammock REST library (and it can really come in handy if you have to use OAuth later) and Json.NET - with its help, the original Json is parsed and the one we really need is selected from LINQ to JSON Well, a very extensive source. In addition, jQuery Templates and Datejs are used to render the stream .

Examples of how this looks can be seen here and here (until they are struck by the habr effect). At this stage of implementation, links to web sites, previews of media resources, quotes from other people's posts and geo-location / Google Places check-in's are correctly displayed.

I hope this blank turns out to be useful for many - it is easy to rewrite it to your favorite language / toolkit and bring it to mind / aesthetic maturity.

Sources: narod.ru/disk/21224545001/gstream.rar.html

Also popular now: