Loading ...
Sorry, an error occurred while loading the content.

5398401 unauthorized error in Placespotter, same code works in Placefinder

Expand Messages
  • r.hertzman
    Jun 27, 2013
    • 0 Attachment
      I'm getting a "401 Unauthorized" error from Placespotter using the C# code below. The odd thing is that the same code works just fine when I change the URL to Placefinder, and the method from PUT to GET. So I think there must be something else going on, since apparently my OAuth code is working fine for Placefinder. Any ideas?

      (Ultimately, I plan to convert this to a multipart/form-data PUT request, so I can use text larger than 2K ish, so if anyone's got some sample code for that, I'd be interested as well. Surprising how few samples are available on the web for Placespotter). Thanks!


      public string GetWOEID()
      {
      OAuthBase o = new OAuthBase();

      // Uncomment this block to use Placespotter
      Uri uri = new Uri(string.Format("{0}?{1}",urlBase,
      "documentContent=" + HttpUtility.UrlEncode(text) + "&documentType=text/plain&appid=[...]"));
      string method = "PUT";

      // Uncomment this block to use Placefinder
      //Uri uri = new Uri("http://yboss.yahooapis.com/geo/placefinder?location=Paonia&appid=[...]");
      //String method = "GET";

      // Calculated during signature generation
      string normalizedURL;
      string normalizedParameters;

      // Oauth header elements
      string oauth_timestamp = o.GenerateTimeStamp();
      string oauth_nonce = o.GenerateNonce();
      string oauth_consumer_key = OAuthConsumerKey;
      string oauth_signature = HttpUtility.UrlEncode(o.GenerateSignature(uri, OAuthConsumerKey, OAuthConsumerSecret, null, null,
      method, oauth_timestamp, oauth_nonce, out normalizedURL, out normalizedParameters));

      Uri signedURL = new Uri(string.Format("{0}?{1}&oauth_signature={2}", normalizedURL, normalizedParameters, oauth_signature));

      // The Web request and response objects
      HttpWebRequest request;
      HttpWebResponse response;

      try {
      request = (HttpWebRequest)WebRequest.Create(signedURL);
      request.Method = method;
      request.ContentType = "application/x-www-form-urlencoded";

      // And try the request. Miracle if it works.
      response = (HttpWebResponse)request.GetResponse();

      Stream datastream = response.GetResponseStream();
      StreamReader reader = new StreamReader(datastream);
      string responsetext = reader.ReadToEnd();
      reader.Close();
      datastream.Close();
      response.Close();

      return response.StatusDescription + "\n\n" + responsetext;
      }
      catch (Exception ex)
      {
      return ex.Message;
      }

      }
    • Show all 2 messages in this topic