从刷新令牌PayPal未来付款.net获取访问令牌

时间:2017-04-13 06:05:11

标签: .net paypal paypal-adaptive-payments

当我从Auth代码获取时,将来付款正在使用访问令牌,但是当我从刷新令牌获取它时会导致异常无效的刷新令牌。

我遵循了所有these步骤并尝试了这些ones

var authorizationCodeParameters = new 
          CreateFromAuthorizationCodeParameters();
            authorizationCodeParameters.setClientId(Configuration.ClientId);


   authorizationCodeParameters.setClientSecret(Configuration.ClientSecret);
            authorizationCodeParameters.SetCode(authorizationCode);


            // ### Api Context
            // Pass in a `APIContext` object to authenticate 
            // the call and to send a unique request id 
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly. 
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            var tokenInfo = Tokeninfo.CreateFromAuthorizationCodeForFuturePayments(apiContext, authorizationCodeParameters);
            apiContext.ResetRequestId();


            string r = tokenInfo.refresh_token;
            string a = tokenInfo.access_token;


            Convert.ToBase64String(a);
            apiContext.HTTPHeaders.Add("Authorization", "Bearer " + a);

            //CreateFromRefreshTokenParameters refreshTokenParams = new CreateFromRefreshTokenParameters();
            //Tokeninfo tokenInfonew = new Tokeninfo(); // Create TokenInfo object; setting the refresh token
            //tokenInfonew.refresh_token = "Basic " + "R23AAF1LBOQpLlybly3MzNeWNzHv7L5rdcpQq55bT8VqPwrJnh8TzpKxfNeyVLNV973IfgpxjsK2xUG-52rrpagXREGqlFZJNC5jqe_kc6gEZbV6e-VkF1aQsxImsib7ERhQR3wjPIzxfOCxAKNVQ";

            //var tokenf =   tokenInfonew.CreateFromRefreshToken(apiContext, refreshTokenParams);

            var tokenInfo1 = new Tokeninfo();

            // tokenInfo.refresh_token = "Bearer R23AAF1LBOQpLlybly3MzNeWNzHv7L5rdcpQq55bT8VqPwrJnh8TzpKxfNeyVLNV973IfgpxjsK2xUG-52rrpagXREGqlFZJNC5jqe_kc6gEZbV6e-VkF1aQsxImsib7ERhQR3wjPIzxfOCxAKNVQ";
            CreateFromRefreshTokenParameters refrehCodeParameters = new CreateFromRefreshTokenParameters();
            refrehCodeParameters.setClientId(Configuration.ClientId);
            refrehCodeParameters.setClientSecret(Configuration.ClientSecret);
            refrehCodeParameters.SetGrantType("refresh_token");            
            refrehCodeParameters.SetScope(tokenInfo.scope);
            refrehCodeParameters.SetRefreshToken(string.Format("{0} {1}", tokenInfo.token_type, tokenInfo.refresh_token));



            var tokenf = tokenInfo.CreateFromRefreshToken(apiContext, refrehCodeParameters);

            var accessToken = string.Format("{0} {1}", tokenf.token_type, tokenf.access_token);

            var futurePaymentApiContext = Configuration.GetAPIContext(accessToken);

0 个答案:

没有答案