首页 文章

远程服务器返回错误:(401)未经授权 . 使用Paypal Rest APi时

提问于
浏览
0

我正在使用Paypal Rest APi . 当我尝试获取访问令牌时,它会给我未经授权的错误 . 索引页面

@Html.ActionLink("Pay with Paypal Account", "PaymentWithPaypal", "Paypal")

web.config中

<configSection>
<section name="paypal" type="PayPal.SDKConfigHandler, PayPal"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSection>

    <paypal>
    <settings>
      <add name="mode" value="sandbox"/>
      <add name="connectionTimeout" value="360000"/>
      <add name="requestRetries" value="1"/>
      <add name="clientId" value="###########"/>
      <add name="clientSecret" value="**********"/>
    </settings>
  </paypal>
  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="my_app.log"/>
      <appendToFile value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date       [%thread] %-5level %logger [%property{NDC}] %message%newline"/>
      </layout>
    </appender>
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="FileAppender"/>
    </root>
  </log4net>
  <system.web>
    <securityPolicy>
      <trustLevel name="Full" policyFile="internal"/>
    </securityPolicy>

错误消息是

The remote server returned an error: (401) Unauthorized.

描述:执行当前Web请求期间发生未处理的异常 . 请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息 .

异常详细信息:PayPal.IdentityException:远程服务器返回错误:(401)未经授权

错误发生在以下行

string accessToken = new OAuthTokenCredential(ClientId, ClientSecret, GetConfig()).GetAccessToken();

在Inspect元素中给出了以下消息 .

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

我用来集成Rest Api的代码可以在这里找到http://www.codeproject.com/Articles/870870/Using-Paypal-Rest-API-with-ASP-NET-MVC

任何人都可以帮我解决这个问题 .

1 回答

  • 1

    尝试以下代码

    Dictionary<string, string> payPalConfig = new Dictionary<string, string>();
           payPalConfig.Add("mode", "sandbox");
           OAuthTokenCredential tokenCredential = new AuthTokenCredential("myCliedId","myClientSecret", payPalConfig);
           string accessToken = tokenCredential.GetAccessToken();
    

相关问题