简体   繁体   中英

paypal access token not returning

I trying to send a payment with my test application. Im using the paypal java sdk package.

Im not receiving my access token. Im receiving only the bearer token, Bearer WesirDWp61YcTr8N8XWZHnPk7tCch.ZgcMvLfyp-FRA : appId : APP-80W284485P519543T

Thus when I try to send a payment Im getting and 401 authorization error because of no access token. The first time I sent the request it returned the access token but every subsequent attempt brings this error:

Java exception "com.paypal.core.rest.PayPalRESTException: Error code : 401
with response : Server returned HTTP resp" when calling method "create" with signature "(Ljava.lang.String;)Lcom.paypal.api.payments.Payment;" in class
"com.paypal.api.payments.Payment".

I do not understand what is happening here . Am I completely missing the boat here?

Thank You for any response.

The bearer token is the access token, more specifically it is the type of access token returned. As per the REST API Reference (which is what the java sdk calls), the call to the oauth end point returns:

{ "scope": " https://api.paypal.com/v1/payments/ .* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/ .*", "access_token": "EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG", "token_type": "Bearer", "app_id": "APP-6XR95014SS315863X", "expires_in": 28800 }

The SDK combines the two fields and returns them as the "Bearer token".

This bearer token is all you need to access the REST APIs (with some restrictions based on the permissions/scopes requested and how the bearer token was requested, however that is dependent on creation call). Pass the bearer token in the authorization header: "Authorization: Bearer EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG"

Hit this URL with POST Request on Postman. POST https://api.sandbox.paypal.com/v1/oauth2/token On Authorization choose basic auth and enter the username as a clientID and password as a ClientSecret. In Header set Content-Type: application/x-www-form-urlencoded In Body seelect x-www-form-urlencoded and write grant_type: client_credentials after that send request you will get the access_token

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM