我知道有沒有.NET C#的任何四方sdk。 我正在做基於開發人員參考,但我沒有做到這一點在請求令牌期間,我不斷收到錯誤。 我正在使用VS 2008和正在開發的服務器。我搜索此錯誤之前,因爲URL重寫,但我不是託管在IIS中,我也有檢查web.config,也沒有運氣。請幫忙,謝謝。Foursquare SDK for .net
這是我的錯誤:用於訪問路徑「/登錄」
的HTTP動詞POST是不允許的。
這是我實現:
HttpWebRequest request = null;
HttpWebResponse response = null;
StreamReader responseStream = null;
ASCIIEncoding ascii = null;
string key = ConfigurationManager.AppSettings["key"];
string secret = ConfigurationManager.AppSettings["secret"];
string callback = ConfigurationManager.AppSettings["callback"];
string obtainTokenUrl = ConfigurationManager.AppSettings["obtainTokenUrl"];
try
{
string postData = "client_id=" + key + "&response_type=code&redirect_uri=" + callback;
ascii = new ASCIIEncoding();
byte[] postBytes = ascii.GetBytes(postData);
try
{
request = WebRequest.Create(obtainTokenUrl) as HttpWebRequest;
}
catch (UriFormatException)
{
request = null;
}
if (request == null)
{
throw new ApplicationException("Invalid URL: " + obtainTokenUrl);
}
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
//add post data to request
Stream postStream = request.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Close();
response = (HttpWebResponse)request.GetResponse();
Encoding encode = Encoding.GetEncoding("utf-8");
responseStream = new StreamReader(response.GetResponseStream(), encode);
Response.Write(responseStream.ReadToEnd());
您正在編碼oauth自己?有好的圖書館爲你做這個。還有一個類似的老問題http://stackoverflow.com/questions/3611731/foursquare-oauth-authentication-net-sample – Rup 2010-12-16 13:28:58