0
我想建立一個網站,使用調查猴子API方法來顯示數據,爲此,我正在建立一個類庫,在其中我將調用一個(只有一個來自某個控制器)方法,該方法應該執行用戶的oauth (我在調查猴網站中提到的3步過程是成功的),但是現在我只想從控制器調用一個方法到類庫中的一個方法,該方法將執行用戶的oauth並設置可以稍後使用的令牌用於API方法。我的代碼是這樣的類庫:如何在類庫中使用重定向(url)方法?
HttpContext.Current.Response.Redirect(urlToAuthorize);
//what should be here (I should wait till the user gives credentials and authorize so that I can get the query string)
string tempAuthCode = HttpContext.Current.Session["code"].ToString();
if (!verifyRedirectedTempCode(tempAuthCode))
{
return "Not a valid Token";
}
else
{
try
{
var webRequest = GetWebRequestForHttpPostOfSurveyMonkeyToken(ApiKey,ClientSecret,tempAuthCode,RedirectUri,ClientId,GrantType,ContentType,WebRequestMethod);
using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())
{
string tokenJson = new StreamReader(response.GetResponseStream()).ReadToEnd();
AccessToken accesstokenObj = JsonConvert.DeserializeObject<AccessToken>(tokenJson);
return accesstokenObj.Token.ToString();
}
}
catch
{
return null;
}
}
}
重定向後,它不是等待用戶authorize.So,它不工作完全按照我的想法。如何等待用戶授權並收集此查詢字符串?它應該在類庫本身完成。
ohhh ok謝謝... – user3324848