在为RequestToken调用Google API时出现签名无效错误

时间:2012-04-18 23:58:27

标签: c# oauth google-api

我正在为RequestToken调用Google API,而我正在使用OAuhtBase生成我的签名。我的代码如下:

 public Uri BaseURL
        {
            get { return new Uri("https://www.google.com/accounts/OAuthGetRequestToken");  }
            set { }
        }
        public string ConsumerKey
        {
            get { return "anonymous"; }
        }
        public string Nonce
        {
            get { return oAuthBase.GenerateNonce(); }
        }
        public string SignatureMethod
        {
            get { return "HMAC-SHA1"; }
        }
        public string Signature { get
        {
            string url;
            string requestParams;
            return HttpUtility.UrlEncode(oAuthBase.GenerateSignature(BaseURL, ConsumerKey, ConsumerSecret, string.Empty, string.Empty,
                                               "GET", Timestamp, Nonce, out url, out requestParams));
        }
        }
        public string Timestamp
        {
            get { return oAuthBase.GenerateTimeStamp(); }
        }
        public string Scope
        {
            get { return "https://www.googleapis.com/auth/userinfo.profile"; }
        }
        public string Callback
        {
            get { return "www.contestfactory.com"; }
        }


          public string GenerateURL()
          {

             var returnURL = new StringBuilder(BaseURL.ToString());

             returnURL.Append("?");
             returnURL.Append("oauth_consumer_key=" + ConsumerKey);
             returnURL.Append("&oauth_signature_method=" + SignatureMethod);
             returnURL.Append("&oauth_signature=" + Signature);
             returnURL.Append("&oauth_timestamp=" + Timestamp);
             returnURL.Append("&oauth_nonce=" + Nonce);
             returnURL.Append("&oauth_callback=" + Callback);
             returnURL.Append("&scope=" + Scope);

              return returnURL.ToString();

          }

现在,当我的javascript尝试浏览到此代码生成的URL时。它在浏览器上返回以下错误:

  

signature_invalid   base_string:GET&安培; HTTPS%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetRequestToken&安培; oauth_callback%3Dwww.contestfactory.com%26oauth_consumer_key%3Danonymous%26oauth_nonce%3D400857%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1334790691%26scope%3Dhttps% 253A%252F%252Fwww.googleapis.com%252Fauth%252Fuserinfo.profile

我不确定签名的哪一部分可能是错误的,因为我传递了所有必需的参数,它们都是基本的字符串。任何想法?

0 个答案:

没有答案