Hello Robert
Authenticating to Groups Settings API is a little tricky. Here is a sample
code doing the updation.
// Get the Authorization URL
String authorizeUrl = new GoogleAuthorizationRequestUrl(CLIENT_ID,
CALLBACK_URL, SCOPE).build();
System.out.println("Paste this url in your browser:\n" + authorizeUrl);
// Wait for the authorization code
System.out.println("Type the code you received here: ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in
));
String authorizationCode = in.readLine();
// Exchange for an access and refresh token
AccessTokenResponse authResponse = new GoogleAuthorizationCodeGrant(
TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET,
authorizationCode,
CALLBACK_URL).execute();
System.out.println("Access token: " + authResponse.accessToken);
GoogleAccessProtectedResource accessProtectedResource =
new GoogleAccessProtectedResource(
authResponse.accessToken, TRANSPORT, JSON_FACTORY, CLIENT_ID,
CLIENT_SECRET, authResponse.refreshToken);
// Make an authenticated request
Groupssettings settings = Groupssettings.builder(TRANSPORT, JSON_FACTORY
)
.setApplicationName("GoupsSettingsJavaSample")
.setHttpRequestInitializer(accessProtectedResource)
.build();
Get getRequest = settings.groups().get("Your Group");
getRequest.set("alt", "json");
Groups group = getRequest.execute();
System.out.println(group.getName());
group.setWhoCanPostMessage("ANYONE_CAN_POST");
Update updateRequest = settings.groups().update("Your Group", group);
updateRequest.set("alt", "json");
group = updateRequest.execute();
There are few things to note here . You have to use Groupssettings builder
function to build the client. You need to assign the
accessProtectedResource to the client as it contains your access token.
Other than that for update you cannot set a parameter in empty object and
call update. You need to modify a retrieved Groups object update the
required fields and call update. There are other ways to update where you
don't can do it without retrieving the group first. Refer
this<http://code.google.com/googleapps/domain/group_settings/v1/using_api.html#GA_group_update_settings>.
I hope it helps.
Let us know if there is any other issue.
Thanks
Gunjan Sharma
--
You received this message because you are subscribed to the Google Groups
"Google Apps Domain Information and Management APIs" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-apps-mgmt-apis/-/2tlMO7J-f-cJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-apps-mgmt-apis?hl=en.