问题
I'm trying to request an authentication token:
public static void RequestAuthorization(WebConsumer consumer)
{
var extraParams = new Dictionary<string, string> {
{ "oauth_token", string.Empty},
{ "oauth_callback", "http://www.ihighfive.com/" },
};
var req = consumer.PrepareRequestUserAuthorization(callback, extraParams, null);
consumer.Channel.Send(req);
}
Problem is, when I run .PrepareRequestUserAuthorization() I get the following error
Expected IProtocolMessage message but received no recognizable message.
Inspecting the request/response with Fiddler, I can see that the response returns(values obfusticated):
{ "oauth_token" : "this-is-the-oauth-token",
"oauth_token_secret" : "this-is-the-oauth-secret-token",
"oauth_callback_confirmed" : true,
"urlToSendUserTo" : "http://blah.blah.com/api/OAuthAuthorizeToken.aspx?oauth_token=token-value-is-really-long"}
To me, this appears to be a good response. If I visit the urlToSendUserTo, it works, and then passes me through to my initial callback url. So I guess DNOA is having problems parsing the response, but I can't see why.
回答1:
What protocol is the server using? It's not OAuth 1.0 but you're using OAuth 1.0 classes in DotNetOpenAuth. OAuth 1.0 mandates that the response be in application/x-www-form-urlencoded format but in your snippet of the response it's clearly in JSON instead.
Also, I've never seen the urlToSendUserTo parameter in any spec, and I don't know why you're sending an empty oauth_token as an extra parameter in the request.
It seems like you and/or the server are speaking very different languages.
来源:https://stackoverflow.com/questions/9233943/dotnetopenauth-expected-iprotocolmessage-message