无法使用.NET客户端库检索Google网上论坛的设置 [英] Unable to retrieve settings for Google Group using .NET client library
问题描述
我目前正在编写一个系统,该系统将负责创建和维护Google网上论坛,使其与我们的内部系统绑定(并与之保持同步).
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.
到目前为止,第一部分可以正常工作,但是第二部分-使用Google网上论坛设置API失败.似乎在期望JSON时总是接收XML数据.这会导致反序列化失败,从而引发异常.
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.Apis.Groupssettings.v1 1.4.0.28227(1.4.0-beta)
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("samplegroup@example.com").Execute();
在最后一行之前一切都很好,该行失败并显示以下错误:
All is well until that last line, which fails with the following error:
- GoogleApiException:发生错误,但无法反序列化错误响应.
- InnerException:Newtonsoft.Json.JsonReaderException:解析值:<时遇到意外字符.路径",第0行,位置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: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?
推荐答案
.NET客户端库不支持xml,而Groupssettings API同时支持atom和json.我对您的建议是执行以下操作:
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:
var getRequest = settingsService.Groups.Get("samplegroup@example.com");
getRequest.Alt = "json";
var settings = getRequest.Execute();
这篇关于无法使用.NET客户端库检索Google网上论坛的设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!