Web客户端失败的物理设备和仿真器
UPDATE:Web客户端失败的物理设备和仿真器
Maybe it's just me not understanding how oAuth works? I tried running the query manually on http://www.apikitchen.com and I get a 400 error there too! Just to be sure, am I constructing the URL correctly here?
POST URL:
https://api.bufferapp.com/1/oauth2/token.json?client_id=[hidden]&client_secret=[hidden]&redirect_uri=http://apps.joel-murphy.com/buffer/code/success.php&code=[the access code I get from buffer starting with 1/]&grant_type=authorization_code
原帖:
我建立这需要从一个网站数据使用的Windows Phone应用程序。该网站使用oAuth来验证用户身份。
我使用内置的Web浏览器控件进行GET请求来验证用户身份。官方文档要求URL结构如下:
GET https://bufferapp.com/oauth2/authorize ? client_id=...& redirect_uri=...& response_type=code
我的应用程序的这部分工作。虽然从服务器交换访问令牌的授权令牌时,我遇到了问题。官方文档需要的URL结构是这样的:
POST https://api.bufferapp.com/1/oauth2/token.json ? client_id=...& client_secret=...& redirect_uri=...& code=...& grant_type=authorization_code
纠正我,如果我错了,但是从我知道有没有办法使从浏览器POST请求,除非提交表单。出于这个原因,我决定使用WebClient
类将数据提交给服务器。
The remote server returned an error: NotFound
没有人有任何的想法有什么不对下面的代码:但是,不管我在实际设备上或在Visual Studio模拟器我总是收到以下错误运行我的代码?我花了超过5个小时,试图解决这个错误,但似乎没有任何工作。
我正在使用的代码:
WebClient wc = new WebClient();
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
wc.UploadStringAsync(new Uri(access_token_url), "POST", GetPostParameters());
void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
try
{
MessageBox.Show(e.Result);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
string GetPostParameters()
{
string data = "";
data += "client_id="+client_id + "&";
data += "client_secret=" +client_secret + "&";
data += "redirect_uri=" + redirect_uri+ "&";
data += "code=" + App.AccessToken + "&";
data += "grant_type=authorization_code";
return data;
}
没有人有任何的想法有什么不对?这让我疯狂起来,这真是让人羞耻,因为现在这种技术已经成为现实,oauth必须如此复杂。
在此先感谢。
你可以尝试URL编码redirect_uri变量?
感谢您的回复。我尝试将代码更改为此,但我仍然得到完全相同的错误:data + =“redirect_uri =”+ HttpUtility.UrlEncode(redirect_uri)+“&”; – 2012-07-08 15:30:00
我刚更新了OP,do你认为你可以快速浏览一下吗? – 2012-07-08 15:50:50
你没有在更新的文章中编码你的URL,编码的URL应该是http%3A%2F%2Fapps.joel-mur phy.com%2Fbuffer%2Fcode%2Fsuccess.php – wooncherk 2012-07-08 15:58:03
有几个OAuth包装器[包括这一个](http://localangle.codeplex.com/SourceControl/changeset/view/17743#210860)可以简化整个过程 - 它可能是值得使用类似的东西以解决签署问题 – 2012-07-08 17:23:56
干杯队友,我现在检查一下,并尽快报告:) – 2012-07-08 17:24:44
我在我的解决方案中添加了OAuthWebRequest类,但它包含99个错误,我不知道如何解决:(谢谢无论如何 – 2012-07-08 17:38:04