4

Post(Google+) not working. I tried to implement post using Google+ Domains API v1 (https://developers.google.com/+/domains/getting-started )

Sending the request works, but GetResponse(), I get error like:

The remote server returned an error: (400) Bad Request.

I am trying using the below sample C# code that I got from Google+ API plus.me

var url = "https://www.googleapis.com/plusDomains/v1/people/me/activities?";
var googleParameters = AppendKeyvalue("access_token", access_token) + AppendKeyvalue("message", message);
var fullurl = url + googleParameters;

HttpWebRequest request= (HttpWebRequest)HttpWebRequest.Create(fullurl);
request.ContentType = " application/x-www-form-urlencoded ";
request.Method = "POST";
UTF32Encoding utfenc = new UTF32Encoding();

byte[] byteArray = utfenc.GetBytes(fullurl);
Stream postStream = request.GetRequestStream();
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
WebResponse response = request.GetResponse();

public static string AppendKeyvalue(string key, string value)
{
    return string.Format("{0}={1}&", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(value));
}

For creating new post and comment I am referring this url https://developers.google.com/+/domains/posts/creating. I tried to figure out a fix for it however the solution has not worked so far.

2
  • 1
    In the linked entry, it says "The request was bad because I used UTF32Encoding instead of UTF8Encoding when converting the parameter string to byte[] before writing to Stream. With UTF8Encoding works good. :)" But you are still using UTF32Encoding
    – NineBerry
    Dec 1, 2015 at 15:47
  • 1
    Also, you are using FullURL for buth the uri and the post body while the linked example does only use the parameters for the post body.
    – NineBerry
    Dec 1, 2015 at 15:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.