2013-05-28 68 views
0

我正在嘗試使用DotNetOpenAuth與Twitter進行通信的第一階段。 每當我打電話給我這個方法,我收到以下錯誤:DotNetOpenAuth Twitter RequestUserAuthorization ProtocolException 403錯誤

ProtocolException發生 遠程服務器返回一個錯誤:(403)禁止。

public string SendConsumerAuthentication() 
{ 
    ServiceProviderDescription serviceProvider = GetServiceDescription(); 

    string applicationKey = settingsManager.GetApplicationKey(className); 
    string applicationSecret = settingsManager.GetApplicationSecret(className); 

    // decouple this in future 
    InMemoryTokenManager inMemoryTokenManager = new InMemoryTokenManager(applicationKey, applicationSecret); 

    var consumer = new DesktopConsumer(serviceProvider, inMemoryTokenManager); 
    string uri = string.Empty; 
    string requestToken = string.Empty; 

    var requestArgs = new Dictionary<string, string> { 
     //need to pass this as extra, but leave the value blank 
     { "oauth_token", string.Empty} 
    }; 

    //request access 
    try 
    {     
     uri = consumer.RequestUserAuthorization(requestArgs, null, out requestToken).AbsoluteUri; 
    } 
    catch (Exception) 
    { 
     uri = null;     
    } 

    return uri; 
} 

我想知道我錯過了什麼?

回答

0

更改我的端點解決了這個問題,

來源:

public override ServiceProviderDescription GetServiceDescription() 
    { 
     return new ServiceProviderDescription 
     { 
      AccessTokenEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/access_token", HttpDeliveryMethods.PostRequest), 
      RequestTokenEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/authorize", HttpDeliveryMethods.PostRequest), 
      UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/access_token", HttpDeliveryMethods.PostRequest), 
      TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, 
      ProtocolVersion = ProtocolVersion.V10 
     }; 
    } 

要:

public override ServiceProviderDescription GetServiceDescription() 
    { 
     return new ServiceProviderDescription 
     { 
      AccessTokenEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/access_token", HttpDeliveryMethods.PostRequest), 
      RequestTokenEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/request_token", HttpDeliveryMethods.PostRequest), 
      UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/authorize", HttpDeliveryMethods.PostRequest), 
      TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, 
      ProtocolVersion = ProtocolVersion.V10 
     }; 
    }