I've been using the Google Blogger API v2 for a long time, using GDATA to authenticate and post new posts. However, this is not supported now anymore and they are requiring an OAuth authentication. Unfortunately I cannot find any .Net documentation I fully understand. I followed them as best as I could, and I don't see any errors, so I do not know what else to try, please help me.
My first approach was to go like this: Google.GData.Client.GDataRequestException - Authentication suddenly fails in old code Here an example for Google Spread Sheets is given. However, I do not know with what to replace the line "var service = new SpreadsheetsService(null)", since I do not know if there is a Blogger service.
In the second approach I first got an OAuth2 token like before and then followed the description from https://developers.google.com/blogger/docs/3.0/using?hl=de about publishing posts. So I created a WebRequest as follows:
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = "POST";
http.Headers.Add("Authorization", "Bearer " + token);
var vm = new { kind = "blogger#post", blog = new { id = "id" }, title = "Testtitle", content = "testcontent" };
var dataString = JsonConvert.SerializeObject(vm);
string parsedContent = dataString;
ASCIIEncoding encoding = new ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(parsedContent);
Stream newStream = http.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
var response = http.GetResponse();
var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
But here, I got 403 (not allowed). Why?
Thanks in advance! Best, Oliver