无法使用.NET客户端库检索Google Group的设置

时间:2023-01-30 19:18:15

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.

我目前正在编写一个系统,负责创建和维护Google网上论坛,使其与我们的内部系统相关联(并与之同步)。

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.

到目前为止,第一部分正常工作,但第二部分 - 使用Google网上论坛设置API - 失败。它似乎总是在期待JSON时接收XML数据。这导致无法反序列化,因此抛出异常。

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)

我有客户端库的最新版本(在撰写本文时):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("samplegroup@example.com").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.
  • GoogleApiException:发生错误,但无法反序列化错误响应。
  • InnerException: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
  • InnerException:Newtonsoft.Json.JsonReaderException:解析值时遇到意外的字符:<。路径'',第0行,第0位。

Using Fiddler, I have observed that this is the response:

使用Fiddler,我观察到这是响应:

<?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:examplegrp@example.com</id>
 <title>Groups Resource Entry</title>
 <content type="text">An example group</content>
 <author>
  <name>Google</name>
 </author>
 <apps:email>examplegrp@example.com</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?

我做错了什么,如果有的话?

1 个解决方案

#1


3  

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:

.NET客户端库不支持xml,而Groupssettings API支持atom和json。我的建议是做以下事情:

var getRequest = settingsService.Groups.Get("samplegroup@example.com");
getRequest.Alt = "json";
var settings = getRequest.Execute();

#1


3  

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:

.NET客户端库不支持xml,而Groupssettings API支持atom和json。我的建议是做以下事情:

var getRequest = settingsService.Groups.Get("samplegroup@example.com");
getRequest.Alt = "json";
var settings = getRequest.Execute();