我正在尝试创建一个 asp.net mvc 3 网站来跟踪用户在调查猴子中创建的调查。所以,我正在尝试访问我需要通过调查猴子的 oauth 传递的 API。我是这个概念的新手。我已经阅读过它。对我来说问题是我试图通过 3 获取访问令牌调查 moneky 开发者网站中提到的步骤过程,但我无法传递参数。我收到错误,授权请求失败:缺少必需的参数 redirect_uri 和/或 client_id。我在这里看到了同样的问题但找不到正确的答案。
string surveymonkeypass = "http://localhost";
string client_id = "REDACTED";
string response_type = "code";
string api_key = "REDACTED";
string url = "https://api.surveymonkey.net/oauth/authorize";
string auth_dialog_uri = string.Format("redirect_uri={0}&client_id={1}&response_tpe={2}&api_key={3}", HttpUtility.UrlEncode(surveymonkeypass), HttpUtility.UrlEncode(client_id), HttpUtility.UrlEncode(response_type), HttpUtility.UrlEncode(api_key));
url = url + "?" + "redirect_uri=" + HttpUtility.UrlEncode(surveymonkeypass) + "&client_id=" + HttpUtility.UrlEncode(client_id) + "&response_tpe=" + HttpUtility.UrlEncode(response_type) + "&api_key=" + HttpUtility.UrlEncode(api_key);
System.Diagnostics.Process.Start(url);
我尝试的另一个块是,我得到授权请求失败:
string SM_API_BASE = "https://api.surveymonkey.net";
string AUTH_CODE_ENDPOINT = SM_API_BASE + "/oauth/authorize" + "?";
string auth_dialog_uri = string.Format("redirect_uri=http://localhost:57390/Survey/Create&client_id=REDACTED&response_type=code&api_key=uREDACTED");
WebRequest webRequest = WebRequest.Create(AUTH_CODE_ENDPOINT);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(auth_dialog_uri);
webRequest.ContentLength = bytes.Length;
using (Stream outputStream = webRequest.GetRequestStream())
{
outputStream.Write(bytes, 0, bytes.Length);
StreamReader readStream = new StreamReader(outputStream, Encoding.UTF8);
ViewBag.Message = (readStream.ReadToEnd());
}