ドキュメントに従って、Google API を使用してカレンダーを作成しようとしています。クライアント ライブラリの使用を避け、カスタム Web リクエストを介して API とのすべての通信を行うようにしていますが、これまでのところうまく機能していますが、この特定のライブラリでは「解析エラー」に苦しんでいます。
クライアント ライブラリ ( service.calendars().insert(...) )を使用するソリューションを参照しないでください。
これは私のコードの単純化されたバージョンです (まだ動作していません):
var url = string.Format
(
"https://www.googleapis.com/calendar/v3/calendars?key={0}",
application.Key
);
var httpWebRequest = HttpWebRequest.Create(url) as HttpWebRequest;
httpWebRequest.Headers["Authorization"] =
string.Format("Bearer {0}", user.AccessToken.Token);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json";
httpWebRequest.CookieContainer = new CookieContainer();
// Obviously the real code will serialize an object in our system.
// I'm using a dummy request for now,
// just to make sure that the problem is not the serialization.
var requestText =
"{" + Environment.NewLine
+ "\"summary\": \"test123\"" + Environment.NewLine
+ "}" + Environment.NewLine
;
using (var stream = httpWebRequest.GetRequestStream())
using (var streamWriter = new System.IO.StreamWriter(stream))
{
streamWriter.Write(System.Text.Encoding.UTF8.GetBytes(requestText));
}
// GetSafeResponse() is just an extension that catches the WebException (if any)
// and returns the WebException.Response instead of crashing the program.
var httpWebResponse = httpWebRequest.GetSafeResponse();
ご覧のとおり、シリアル化されたオブジェクトを送信することは今のところあきらめており、非常に単純なダミーのリクエストで動作させようとしています。
{
"summary": "test123"
}
それでも、応答はまだ次のとおりです。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
accessToken は有効で期限切れではありません。アプリケーション キーは正しいです。
私は何が間違っているか、欠けていますか?
前もって感謝します、