1

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

Community
  • 1
  • 1
Oliver
  • 118
  • 11
  • Like I said I think the second approach should work ... Problem is I cannot add the email address from my developer console as blog admin ... i can only send an invite to this email but I cannot accept it ... anyone any tips for this? – Oliver May 31 '15 at 18:29
  • what is the base address you are passed... – Devi Prasad Jul 17 '15 at 07:28
  • I tried your code it returns Unauthorized error. let me know what is the url passed to baseAddress.... – Devi Prasad Jul 21 '15 at 05:03

0 Answers0