Skip to content

Instantly share code, notes, and snippets.

@soundTricker
Created October 24, 2013 02:53
Show Gist options
  • Save soundTricker/7130533 to your computer and use it in GitHub Desktop.
Save soundTricker/7130533 to your computer and use it in GitHub Desktop.
Google+ Domain API with Apps Script
var SCOPE_PLUS_ME = "https://www.googleapis.com/auth/plus.me";
var SCOPE_PLUS_PROFILES_READ = "https://www.googleapis.com/auth/plus.profiles.read";
var SCOPE_PLUS_CIRCLES_READ = "https://www.googleapis.com/auth/plus.circles.read";
var SCOPE_PLUS_CIRCLES_WRITE = "https://www.googleapis.com/auth/plus.circles.write";
var SCOPE_PLUS_STREAM_READ = "https://www.googleapis.com/auth/plus.stream.read";
var SCOPE_PLUS_STREAM_WRITE = "https://www.googleapis.com/auth/plus.stream.write";
var SCOPE_PLUS_MEDIA_UPLOAD = "https://www.googleapis.com/auth/plus.media.upload";
var SCOPES = [SCOPE_PLUS_ME,SCOPE_PLUS_STREAM_WRITE].join("+");
var USER_ID = "me";
var API_KEY = ScriptProperties.getProperty("apiKey");
var apiName = "GPlusDomainApp6";
function test() {
var oauthConfig = UrlFetchApp.addOAuthService(apiName);
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=" + encodeURI(SCOPES));
oauthConfig.setAuthorizationUrl('https://accounts.google.com/OAuthAuthorizeToken');
oauthConfig.setAccessTokenUrl('https://www.google.com/accounts/OAuthGetAccessToken');
var optoins = {
method : "get",
oAuthServiceName : apiName,
oAuthUseToken: "always",
};
//get profile.
var res = UrlFetchApp.fetch("https://www.googleapis.com/plus/v1domains/people/" + USER_ID + "?key=" + API_KEY ,optoins);
Logger.log(res.getContentText());
var messagePostOptions = {
method : "post",
oAuthServiceName : apiName,
oAuthUseToken: "always",
contentType : "application/json",
payload : JSON.stringify({
"object": {
"originalContent": "post from gas!!!"
},
"access": {
"domainRestricted": true
}
})
};
//post activity.
res = UrlFetchApp.fetch("https://www.googleapis.com/plus/v1domains/people/me/activities?key=" + API_KEY , messagePostOptions);
Logger.log(res.getContentText());
}
@praxmehta
Copy link

When we I added "apiKey" and I received this kind of error "Uncaught ReferenceError: ScriptProperties is not defined".
Could you please let me know that what I have to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment