开发者

Is it possible to parse a Google+ (Google Plus) profile page?

If you view the source of a Google+ profile page, it appears rather complex. It seems most of the data is kept in a huge JSON-like objects. However, they don't seem to be really JSON, since they don't get recognized when I try to decode them. I am hoping the format is more clear to other people here. How would you go about parsing it? It seems it would fairly trivial, if you know where to start.

Here is a sample profile, for example:开发者_如何学Python http://plus.google.com/104560124403688998123


Here's a PHP API I'm working on. It can download and parse the data for a profile page and people's public relationships.

https://github.com/jmstriegel/php.googleplusapi

The JSON piece is a bit mangled. To generate valid JSON, you basically have to remove the first 5 characters that prevent XSRF attacks and then add in all the nulls that have been removed. Here's the code specific to handling parsing the weird Google Plus JSON responses:

https://github.com/jmstriegel/php.googleplusapi/blob/master/lib/GooglePlus/GoogleUtil.php

Call GoogleUtil::FetchGoogleJSON( $url ) and you'll get back a giant array that you can then pull data from. Using this, it should be trivial to make a proxy service to translate stuff into valid json(p) for you to use in your own apps.


I don't have access to Google+ yet, so I'll just answer the general question - that is, how to parse JSON.

JSON is just JavaScript, so parsing it is as simple as evaluating the script. To do this, use the eval() JavaScript function.

var obj = eval('{"JSON":"goes here"}');

Another option is to leverage a console tool. Popular modern browsers pretty much all have them. I recommend Firebug for Firefox in particular.

Using Firefox, log into Google+, then open the Firebug console. You can use the console's dir() command to create a browseable representation of the data. Ex:

console.dir(eval('{"JSON":"goes here"}'));

Sorry I can't be more specific about how to get a handle on Google+'s JSON in particular; without access to the service, this is about the best I can do blind. Good luck!


Thanks to Jason for the excellent php class which reads a profile page into an array.

I've used this class as a base and then parsed it, based upon Russell Beattie's python code from the original appspot rss feed application.

Code here

A few notes:

  1. I use this to merge G+ and WP feeds, hence writing posts into an intermediate array ($items).
  2. I have a convention of creating a pseudo title in Google Plus posts, by emboldening a line and adding two newlines before writing the post. The function getTitle strips this out as a better formatted title in my website and getSummary produces the rest of the post with duplicating the title.


It's made up of a number of parts, an object describing your picasa images, one describing the fields on your profile, one describing your friends.

Most of the long numbers are the internal IDs of people, posts and photos. For instance, my ID is 105249724614922381234. Other than that, it could be parsed if you needed to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜