Re: Re: Must Blogger.com API be "ON" to work?
"Random(Name)" <[email protected]>
| Newsgroups | gmane.comp.web.blogger.api |
|---|---|
| Message-ID | <[email protected]> |
Hi Andreas S,
Could you please share (sample code) how to post to Blogger with Api v3
with C#? Currently, I (think) I know how to make a new post (using HTTP
Post...), but I don't know how to authorize requests with OAuth 2.0.
(I work with C#).
On Saturday, March 14, 2015 at 8:27:40 AM UTC+7, Andreas S wrote:
>
> Thanks Luke,
>
> I am not attaching the API key at all. Looking at the documentation, the
> API key can't be used when "Adding a Post" to the blog?
> https://developers.google.com/blogger/docs/3.0/using#AddingAPost
>
> It was a good idéa to verify a successful post to the Blogger API. When
> using the API Explorer it did work. A post was added to the blog. This
> should tell that something is working and are enabled?
> Here is the response code from API Explorer:
> http://www.bilddump.se/bilder/20150313232521-195.252.32.111.bmp
>
> Looking at the response, this URL is shown as a POST which confuses me, as
> the API is present in the URL (which can't be used in order to "Adding a
> Post" ?)
> https://www.googleapis.com/blogger/v3/blogs/7438198107440561164/posts?key={YOUR_API_KEY}
>
> Looking at response, I can see those headers and wonder if they are needed:
> request.AddHeader("Content-Encoding", "gzip");
> request.AddHeader("Content-Length", "the length of body here"); //Length of
> body in ASCII
>
> I have done an attempt using the API key but it feels that I have no idéa
> of what I am doing now. I can't find any documentation of a straight
> forward example
> of how to do this. I also say this having in mind my very first post which
> "should work" or have to be extremely close. Also that I can't find any C#
> documentation of
> how to use the Google API library of how to "Adding a Post". I have
> searched Google whole day but can't find anything usuable.
>
> Below code gives this error message: (See screenshot)
> http://www.bilddump.se/bilder/20150313133753-195.252.32.111.bmp
>
> String body = "{" + '"' + "blog" + '"' + ": {" + '"' + "id" +
> '"' + ": " + '"' + "7438198107440561164" + '"' + "}," +
> '"' + "title" + '"' + ": " + '"' + "A new
> post" + '"' + "," +
> '"' + "content" + '"' + ": " + '"' + "With
> <b>exciting</b> content..." + '"' + "}";
> byte[] bytes = Encoding.ASCII.GetBytes(body.ToString());
> int ContentLength = bytes.Length;
>
>
> String requestUrl = "
> https://www.googleapis.com/blogger/v3/blogs/7438198107440561164/posts?key=myAPIkeyGOEShere
> ";
>
> RestSharp.RestClient rc = new RestSharp.RestClient();
> RestSharp.RestRequest request = new RestSharp.RestRequest(
> requestUrl, RestSharp.Method.POST);
> request.AddHeader("Content-Type", "application/json");
> request.AddHeader("Content-Encoding", "gzip"); //Compression
> needed?
> request.AddHeader("Content-Length", ContentLength.ToString()); //Length
> of body in ASCII, perheps needed?
> request.AddBody(body);
>
> request.RequestFormat = RestSharp.DataFormat.Json;
>
> RestSharp.RestResponse restResponse = (RestSharp.RestResponse)
> rc.Execute(request);
> RestSharp.ResponseStatus responseStatus = restResponse.
> ResponseStatus;
>
> MessageBox.Show(restResponse.Content.ToString() + "," +
> restResponse.Content.ToString().Length.ToString() + "," + responseStatus.
> ToString());
>
>
>
>
>
>
>
> Den fredag 13 mars 2015 kl. 02:50:22 UTC+1 skrev Luke:
>>
>> Are you attaching the API key, as a parameter to the request? Have you
>> enabled your endpoint (i.e. your C# program) for the API key?
>>
>> Note that you don't need to set the 'kind' field; that's just part of the
>> response.
>>
>> If you want to verify what a successful post to the Blogger API is like,
>> use the api explorer.
>> https://developers.google.com/apis-explorer/#p/blogger/v3/blogger.posts.insert.
>> You can see the headers attached and what-not if you use developer tools in
>> chrome, for example.
>>
>
--
You received this message because you are subscribed to the Google Groups "Blogger Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/bloggerdev.
For more options, visit https://groups.google.com/d/optout.