DotNetOpenAuth Twitter RequestUserAuthorization ProtocolException 403错误

时间:2013-05-28 08:30:18

标签: c# twitter dotnetopenauth class-library

我正处于尝试使用DotNetOpenAuth与Twitter沟通的第一阶段。 每当我调用此方法时,我都会收到以下错误:

发生了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;
}

我想知道我错过了什么?

1 个答案:

答案 0 :(得分: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
        };
    }