I'm currently writing a system which will be responsible for creating and maintaining Google Groups in such a way that they tie into (and are in sync with) our internal systems.
As part of this, I am currently working on simply creating a group, changing its settings and then allocating some members to the group.
So far, the first part works correctly but then the second part - using the Google Groups Settings API - fails. It seems that it is always receiving XML data when it is expecting JSON. This results in a failure to deserialize and thus an exception is thrown.
I have the latest version (at time of writing) of the client library: Google.Apis.Groupssettings.v1 1.4.0.28227 (1.4.0-beta)
This is some sample code that's failing:
// OAuth2.0/service account stuff here
var initializer = //...;
var settingsService = new GroupssettingsService(initializer);
var settings = settingsService.Groups.Get("[email protected]").Execute();
All is well until that last line, which fails with the following error:
- GoogleApiException: An Error occurred, but the error response could not be deserialized.
- InnerException: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Using Fiddler, I have observed that this is the response:
<?xml version="1.0" encoding="UTF-8"?>
<errors xmlns="http://schemas.google.com/g/2005">
<error>
<domain>GData</domain>
<code>invalid</code>
<internalReason>A system error has occurred</internalReason>
</error>
</errors>
I think the fact its an error might be down to the fact the group is newly created, but I've tried with an older one as well and got the following:
HTTP/1.1 200 OK
Expires: Thu, 18 Jul 2013 13:00:13 GMT
Date: Thu, 18 Jul 2013 13:00:13 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
ETag: "w9Sr8O0S9lDi5Pcv_43hXQkUtmA/TS0CjusfGhj0vG_aNIJAXkmNM4s"
Content-Type: application/atom+xml; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 1811
Server: GSE
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006" xmlns:gd="http://schemas.google.com/g/2005">
<id>tag:googleapis.com,2010:apps:groupssettings:GROUP:[email protected]</id>
<title>Groups Resource Entry</title>
<content type="text">An example group</content>
<author>
<name>Google</name>
</author>
<apps:email>[email protected]</apps:email>
<apps:name>An example group</apps:name>
<apps:description/>
<apps:whoCanJoin>CAN_REQUEST_TO_JOIN</apps:whoCanJoin>
<apps:whoCanViewMembership>ALL_MANAGERS_CAN_VIEW</apps:whoCanViewMembership>
<apps:whoCanViewGroup>ALL_MEMBERS_CAN_VIEW</apps:whoCanViewGroup>
<apps:whoCanInvite>ALL_MANAGERS_CAN_INVITE</apps:whoCanInvite>
<apps:allowExternalMembers>false</apps:allowExternalMembers>
<apps:whoCanPostMessage>ANYONE_CAN_POST</apps:whoCanPostMessage>
<apps:allowWebPosting>true</apps:allowWebPosting>
<apps:maxMessageBytes>5242880</apps:maxMessageBytes>
<apps:isArchived>false</apps:isArchived>
<apps:archiveOnly>false</apps:archiveOnly>
<apps:messageModerationLevel>MODERATE_NONE</apps:messageModerationLevel>
<apps:spamModerationLevel>MODERATE</apps:spamModerationLevel>
<apps:replyTo>REPLY_TO_IGNORE</apps:replyTo>
<apps:customReplyTo/>
<apps:sendMessageDenyNotification>false</apps:sendMessageDenyNotification>
<apps:defaultMessageDenyNotificationText/>
<apps:showInGroupDirectory>false</apps:showInGroupDirectory>
<apps:allowGoogleCommunication>false</apps:allowGoogleCommunication>
<apps:membersCanPostAsTheGroup>false</apps:membersCanPostAsTheGroup>
<apps:messageDisplayFont>DEFAULT_FONT</apps:messageDisplayFont>
<apps:includeInGlobalAddressList>true</apps:includeInGlobalAddressList>
</entry>
So even then, it's still not deserializable, and thus doesn't work.
What am I doing wrong, if anything?
The .NET client library doesn't support xml, while the Groupssettings API supports both atom and json. My suggestion for you is to do the following: