5

Google バズに自動投稿する Web アプリを作成しています。

「Oauth dance」で管理する C# ライブラリを作成しましたが、正常に動作し、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();
}

同じデータを使用しても、playground では問題なく動作し、C# コードでは動作しないのはなぜですか? それを修正する方法はありますか?

ありがとう、ステファノ

4

1 に答える 1

0

ヘッダーに OAuth Authorization を 2 回追加しているようです。

ヘッダー文字列にありstring headAuth = "Authorization: OAuth、ヘッダーを追加するreq1.Headers.Add("Authorization", headAuth);と、再度追加されます。

于 2012-06-26T08:19:00.610 に答える