Advertisement
Guest User

Untitled

a guest
Jan 12th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // first call gapi.auth.authorize with immediate:true:
  2.  _checkAuth = function _checkAuth(){
  3.         gapi.auth.authorize({
  4.             client_id : 'XXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
  5.             scope : 'https://www.googleapis.com/auth/plus.login',
  6.             request_visible_actions : 'http://schemas.google.com/CreateActivity',
  7.             immediate : true
  8.         }, function(authResult){
  9.             if(!authResult || authResult.error){
  10.                _signIn();
  11.             }else{
  12.                 _performAction();
  13.             }
  14.         });
  15.     },
  16.  
  17. // if not logged in, call gapi.auth.authorize with immediate:false:
  18. _signIn = function _signIn(){
  19.         gapi.auth.authorize({
  20.             client_id : 'XXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com',
  21.             scope : 'https://www.googleapis.com/auth/plus.login',
  22.             request_visible_actions : 'http://schemas.google.com/CreateActivity',
  23.             immediate : false
  24.         }, function(token){
  25.             gapi.auth.setToken(token);
  26.            _performAction();
  27.         });
  28.     },
  29.  
  30. // create activity
  31. _performAction = function _performAction(){
  32.         gapi.client.load('plus','v1', function(){
  33.             gapi.client.setApiKey('XXXXXXXXXXXXXXXXXXXXXXX');
  34.             var payload = {
  35.                 "type" : 'http://schemas.google.com/CreateActivity'
  36.             };
  37.             payload.target = {
  38.                 "id" : "myappid",
  39.                 "image" : "http://www.example.com/xxxxxxxxxxx.jpg",
  40.                 "type" : 'http://schema.org/CreativeWork',
  41.                 "description" : "description of activity",
  42.                 "name" : "name of activity"
  43.             };
  44.             var args = {
  45.                 'path' : '/plus/v1/people/me/moments/vault',
  46.                 'method' : 'POST',
  47.                 'body' : JSON.stringify(payload),
  48.                 'callback' : function(response) {
  49.                     console.log(response);
  50.                 }
  51.             };
  52.             gapi.client.request(args);
  53.  
  54.         });
  55.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement