2010-09-02 186 views
5

我正在编写一个web应用程序以在Google Buzz上自动关闭。gdata未知授权标头

我写了一个C#库来管理“Oauth舞蹈”,并且它工作正常,我可以得到oauth_token和oauth_token_secret。

我用www.googlecodesamples.com/oauth_playground/来验证 我的oauth_token和oauth_token_secret,它工作正常。我用GET和https://www.googleapis.com/buzz/v1/activities/@me/@self 对它进行了测试 以获取用户的流,它的工作原理。

但现在

我想用我的C#库做相同的,但我总是得到这样 错误:

<?xml version="1.0" encoding="UTF-8"?> 
<errors xmlns="http://schemas.google.com/g/2005"> 
    <error> 
     <domain>GData</domain> 
     <code>invalid</code> 
     <location type="header">Authorization</location> 
     <internalReason>Unknown authorization header</internalReason> 
    </error> 
</errors> 

我的请求头是一样的,从操场之一。

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 

这里的C#代码:

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(); 
} 

为什么它工作正常操场和C#代码不起作用 相同的数据? 任何想法如何解决它?

感谢, 斯特凡诺

+1

你解决了吗?对于我正在面临与配置API相同的问题。 – JochenJung 2010-11-30 13:03:45

回答

0

它看起来像你在你的头相加OAuth授权两次。

在您的标题字符串中您有string headAuth = "Authorization: OAuth,并且当您将标题添加到req1.Headers.Add("Authorization", headAuth);时,您将再次添加它。