I am trying to post photos to google plus via HTTP API(No SDK used) from my webpage.
Here is my code
<html>
<head>
<script></script>
</head>
<body>
<script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) { // XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") { // XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else { // CORS not supported.
xhr = null;
}
return xhr;
}
function PostImageToGoogle()
{
var options = {
"mediaUrl": "https://lh5.googleusercontent.com/-lQJ323klqg4/AAAAAAAAAAI/AAAAAAAABuw/DiqAtVEMftk/photo.jpg"
};
var x = JSON.stringify(options);
var xhr = new XMLHttpRequest();
var gurl = 'https://www.googleapis.com/plusDomains/v1/people/me/media/cloud?access_token=ya29.HQCBp_1_cLr65kgAAAAplbpjbqQhzqWY_tRYprR8O0QJrsIQ93OOJuPmUpE8kRsB8-rzBPeGyjvXtFlia92OoHdoxo8NH7uJRllianuAOju_ayLqrrmGIkUMRlGhGg&key=1364677236854-bc4lhgs7lkjoaohreihbssk8gnims1uf.apps.googleusercontent.com' ;
xhr.open( 'POST', gurl,true );
xhr.onload = function() {
alert( "success" + xhr.responseText );
};
xhr.onerror = function() {
alert("failed" + xhr.responseText);
};
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(x);
}
</script>
<div><label width="80%">Hello! WelCome </label></div>
<form>
<a href="#" onclick="PostImageToGoogle();">post photo</a>
</form>
</body>
</html>
Access_token is generated using the scopes --> plus.me , stream.write, Media.uplode API Enabled are --> Google+ , Google+ Domain
When ever I make request i am getting an error in successcallback as
What is the best approach to share photos on google plus stream without using any SDK. Any sample links ?
Thanks