oauth - Google+ unable to insert moment -
trying example g+ documentation authorize requests using oauth 2.0: on. got unauthorized result. here's output:
request post https://www.googleapis.com/plus/v1/people/me/moments/vault?debug=true&key={your_api_key} content-type: application/json authorization: bearer *my_token* x-javascript-user-agent: google apis explorer { "target": { "url": "https://developers.google.com/+/web/snippet/examples/thing" }, "type": "http://schemas.google.com/addactivity" } response 401 unauthorized cache-control: private, max-age=0 content-encoding: gzip content-length: 93 content-type: application/json; charset=utf-8 date: fri, 01 mar 2013 18:56:34 gmt expires: fri, 01 mar 2013 18:56:34 gmt server: gse www-authenticate: authsub realm="https://www.google.com/accounts/authsubrequest" allowed-scopes="https://www.googleapis.com/auth/plus.login,https://www.google.com/accounts/oauthlogin" { "error": { "errors": [ { "message": "unauthorized" } ], "code": 401, "message": "unauthorized" } } tried revoke google api explorer permissions , authenticated again. nothing changed. doing wrong or g+ apis not yet ready production use?
it looks me apis explorer not work writing app activity google because isn't passing requestvisibleactions field oauth2 flow. can still things manually i'll describe below.
there 2 things need do:
first, ensure rendering sign-in button requestvisibleactions set app activity types inserting. following example shows how render sign-in add activity:
<div id="gconnect"> <button class="g-signin" data-scope="https://www.googleapis.com/auth/plus.login" data-requestvisibleactions="http://schemas.google.com/addactivity" data-clientid="your_client_id" data-callback="onsignincallback" data-theme="dark" data-cookiepolicy="single_host_origin"> </button> </div> next, need construct , write app activity. following example shows using javascript:
var payload = { "target": { "id" : "replacewithuniqueidforaddtarget", "image" : "http:\/\/www.google.com\/s2\/static\/images\/googleyeyes.png", "type" : "http:\/\/schema.org\/creativework", "description" : "the description activity", "name":"an example of addactivity" }, "type":"http:\/\/schemas.google.com\/addactivity", "startdate": "2012-10-31t23:59:59.999z" }; var args = { 'path': '/plus/v1/people/me/moments/vault', 'method': 'post', 'body': json.stringify(payload), 'callback': function(response) { console.log(response); } }; gapi.client.request(args); you can see live demo here:
http://wheresgus.com/appactivitiesdemo
you can learn of activity types documentation here:
https://developers.google.com/+/api/moment-types
update
note live demo has been updated following code , should not directly calling gapi.client.request:
writelistenactivity: function(url){ var payload = { "type": "http://schemas.google.com/listenactivity", } if (url != undefined){ payload.target = { 'url' : url }; }else{ payload.target = { "type": "http:\/\/schema.org\/musicrecording", "id": "uniqueidformusictarget", "description": "a song missing one's family members fighting in american civil war", "image": "https:\/\/developers.google.com\/+\/plugins\/snippet\/examples\/song.png", "name": "when johnny comes marching home" }; } this.writeappactivity(payload); }, writeaddactivity: function(url){ var payload = { "type":"http:\/\/schemas.google.com\/addactivity", "startdate": "2012-10-31t23:59:59.999z" }; if (url != undefined){ payload.target = { 'url' : 'https://developers.google.com/+/plugins/snippet/examples/thing' }; }else{ payload.target = { "id" : "replacewithuniqueidforaddtarget", "image" : "http:\/\/www.google.com\/s2\/static\/images\/googleyeyes.png", "type" : "http:\/\/schema.org\/creativework", "description" : "the description activity", "name":"an example of addactivity" }; } this.writeappactivity(payload); }, writeappactivity: function(payload){ gapi.client.plus.moments.insert( { 'userid' : 'me', 'collection' : 'vault', 'resource' : payload }).execute(function(result){ console.log(result); }); } of particular note gapi.client.plus.moments.insert code replaces gapi.client.request call.
Comments
Post a Comment