【问题标题】:DotNetOpenAuth Twitter RequestUserAuthorization ProtocolException 403 ErrorDotNetOpenAuth Twitter RequestUserAuthorization ProtocolException 403 错误
【发布时间】:2013-05-23 03:33:45
【问题描述】:

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

发生协议异常 远程服务器返回错误:(403) Forbidden。

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;
}

我想知道我错过了什么?

【问题讨论】:

    标签: c# twitter dotnetopenauth class-library


    【解决方案1】:

    更改我的端点解决了问题,

    发件人:

        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
            };
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-23
      • 1970-01-01
      • 2013-12-17
      • 2013-04-05
      • 2012-03-15
      • 1970-01-01
      • 2013-03-30
      • 2015-11-09
      相关资源
      最近更新 更多