Sending Json Data To Google Plus
Solution 1:
You cannot attach images or JSON data to an interactive post. So there is no simple answer to your question.
One option would be to use a normal post instead of an interactive post to share your thumbnail like this - http://googleplusplatform.blogspot.co.uk/2012/05/sharing-rich-content-from-your-android.html, but you will not be able to attach your JSON data to this post either.
A second alternative approach using an interactive post would be to set a publicly visible URL which is the content of the post with builder.setContentUrl(Uri)
. If you create a page which contained the following, for example:
<body itemscope itemtype="http://schema.org/WebPage">
<div itemscope itemtype="http://schema.org/Thing">
<img itemprop="image" src="http://example.com/path/to/thumbnail.jpg" />
<span itemprop="name">Name of your thing</span>
<div class="data">{"INSTRUMENTS":
[{"MINOR":false,"CHANNEL":0,"MAJOR":false,"HIGH_RANGE":-8012206,
"PROGRAM":1,"MAX_KEY":70,"NOTE_LENGTH":150,"LOW_RANGE":-16217748,
"MIN_VELOCITY":60,"MIN_KEY":40},
{"MINOR":false,"CHANNEL":2,"MAJOR":true,"HIGH_RANGE":-2790500,
"PROGRAM":8,"MAX_KEY":90,"NOTE_LENGTH":150,"LOW_RANGE":-12114977,
"MIN_VELOCITY":60,"MIN_KEY":70}]}</div>
</div>
</body>
And made it available at http://example.com/item1
, then you would be able to create an interactive post like this:
PlusShare.Builderbuilder=newPlusShare.Builder(this, plusClient);
// Set call-to-action metadata.
builder.setContentUrl(Uri.parse("http://example.com/thing1"));
builder.addCallToAction("VIEW_ITEM", Uri.parse("http://example.com/thing1"), deepLinkId);
This would mean however that you had to load and parse the page to retrieve your JSON data, which might be better hosted at a different URL.
You could put your JSON data in the deepLinkId itself, but beware that deepLinkId is limited to 512 characters because it is not intended to carry data - only to identify a resource.
Solution 2:
Another approach to Lee's that might work but you could potentially pass the JSON data as the deep link ID for a post. You'd probably want to base64 encode the data, use it as the deep link ID, and then when you capture the incoming deep link, unencode the data and parse it.
You'd have to ensure that the encoded JSON data stayed under 512 characters. Your current JSON snippet comes in at 524 characters when encoded though.
byte[] data = jsonData.getBytes("UTF-8");
String base64Json = Base64.encodeToString(data, Base64.DEFAULT);
if (base64.length() <= 512) {
Intent shareIntent = new PlusShare.Builder(this)
.setText("Lemon Cheesecake recipe")
.setType("text/plain")
.setContentDeepLinkId(base64Json, /** Deep-link identifier */"Lemon Cheesecake recipe", /** Snippet title */"A tasty recipe for making lemon cheesecake.", /** Snippet description */
Uri.parse("http://example.com/static/lemon_cheesecake.png"))
.getIntent();
startActivityForResult(shareIntent, 0);
} else {
// Do something different such as regular share, or try to get encoded length under 512
}
For the incoming link to your app, you would read an unencode this data and make use of it. You'd need to be very careful about validating the data.
Post a Comment for "Sending Json Data To Google Plus"