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

401 unauthorized error in Placespotter, same code works in Placefinder

Expand Messages
  • r.hertzman
    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
    Message 1 of 2 , 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;
      }

      }
    • r.hertzman
      Never heard back on this, so I m bumping it. Since I posted this, I have recoded the routine to include the authorization info in the form header and the
      Message 2 of 2 , Jul 2, 2013
      • 0 Attachment
        Never heard back on this, so I'm bumping it. Since I posted this, I have recoded the routine to include the authorization info in the form header and the parameters in the form body. I am no longer getting the 401 error, which I suppose is progress, but I am now consistently getting a 500 server internal error instead. The documentation says that this is a problem on Yahoo's end, but it's been a couple of days now and I'm still getting a 500 error. Can this error be thrown by some problem in my code? If so, any hints what the problem might be?

        Thanks.


        --- In ysearchboss@yahoogroups.com, "r.hertzman" <hertzman@...> wrote:
        >
        > 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?
        >

        >
        >
        > 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;
        > }
        >
        > }
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.