views:

62

answers:

0

Hi, I'm writing a web app to autopost on google buzz.

I wrote a C# library to manage with "Oauth dance" and in it works fine, I can get oauth_token and oauth_token_secret.

I used www.googlecodesamples.com/oauth_playground/ to validate my oauth_token and oauth_token_secret and it works fine. I tested it with GET and https://www.googleapis.com/buzz/v1/activities/@me/@self to get user's stream, it works.

BUT now

I'm trying to do the same using my C# library but I get always this error:

GData invalid Authorization Unknown authorization header

My request header is the same of the one from playground.

Accept: / Content-Type: application/atom+xml Authorization: OAuth oauth_version="1.0", oauth_nonce="9216320", oauth_timestamp="1283430867", oauth_consumer_key="www.mysite.com", oauth_token="1%2FZodlNmPP96GT11vYaWA0y6QoqKLqNqZ8bNmxknZZZc", oauth_signature_method="HMAC-SHA1", oauth_signature="Tuu82feKNWa4CxoDUyvtIEVODRA%3D" GData-Version: 2.0

Here's the C# code:

string headAuth = "Authorization: OAuth oauth_version=\"1.0\", oauth_nonce=\"9216320\", oauth_timestamp=\"1283430867\", oauth_consumer_key=\"www.mysite.com\", oauth_token= \"1%2FZodlNmPP96GT11vYaWA0y6QoqKLqNqZ8bNmxknZZZc\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature= \"Tuu82feKNWa4CxoDUyvtIEVODRA%3D\"";

        HttpWebRequest req1 =(HttpWebRequest)HttpWebRequest.Create("https://www.googleapis.com/buzz/v1/activities/@me/@self");
        req1.Method = "GET";
        req1.Accept = "*/*";
        req1.ContentType = "application/atom+xml";
        req1.Headers.Add("Authorization", headAuth);
        req1.Headers.Add("GData-Version", "2.0");

        try
        {
            HttpWebResponse response1 =(HttpWebResponse)req1.GetResponse();
            using (var sr = new StreamReader(response1.GetResponseStream()))
            {
                string test_1 = sr.ReadToEnd();
            }
        }
        catch (WebException e)
        {
            Stream objStream = e.Response.GetResponseStream();
            StreamReader objStreamReader = new StreamReader(objStream);
            string err = objStreamReader.ReadToEnd();

        }

Why with the same data it works fine on playground and does not work in C# code? Any idea how to fix it?

Thanks, Stefano