Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // first call gapi.auth.authorize with immediate:true:
- _checkAuth = function _checkAuth(){
- gapi.auth.authorize({
- client_id : 'XXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
- scope : 'https://www.googleapis.com/auth/plus.login',
- request_visible_actions : 'http://schemas.google.com/CreateActivity',
- immediate : true
- }, function(authResult){
- if(!authResult || authResult.error){
- _signIn();
- }else{
- _performAction();
- }
- });
- },
- // if not logged in, call gapi.auth.authorize with immediate:false:
- _signIn = function _signIn(){
- gapi.auth.authorize({
- client_id : 'XXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
- scope : 'https://www.googleapis.com/auth/plus.login',
- request_visible_actions : 'http://schemas.google.com/CreateActivity',
- immediate : false
- }, function(token){
- gapi.auth.setToken(token);
- _performAction();
- });
- },
- // create activity
- _performAction = function _performAction(){
- gapi.client.load('plus','v1', function(){
- gapi.client.setApiKey('XXXXXXXXXXXXXXXXXXXXXXX');
- var payload = {
- "type" : 'http://schemas.google.com/CreateActivity'
- };
- payload.target = {
- "id" : "myappid",
- "image" : "http://www.example.com/xxxxxxxxxxx.jpg",
- "type" : 'http://schema.org/CreativeWork',
- "description" : "description of activity",
- "name" : "name of activity"
- };
- 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);
- });
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement