This is a key provided by Paypal once it has verified our app and account as being authorized in Paypal. We will mostly use access token for REST Api calls in Paypal. Access token helps uniquely identify the authorized bearer of Paypal.
The Fields in Response we receive
- access_token : The unique key we are trying to gain
- token_type : The specification for the key , here it is authorized as being a bearer key.
- app_id : Our app ID, make sure this is the ID of your app.
- expires_in : Each token has an expiry date specified in seconds, for eg. 28800 . So make sure to gain your access token right before you intend to use one.
Before we can get an access token we need to create a developers account and our app on developer.paypal.com from there we will need our app credentials, to get a head start and understand more about each fields we use visit Getting Started.
We will need, (both of these fields are used to authorize our app for payment)
- Username : This is the ClientID of the app we’ve created.
- Password : This is the Secret Key which is obtained along side the ClientID of our app.
Sample HttpPost Request to receive access token in android;
By default use :
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair(“grant_type”, “client_credentials”));
- For Sandbox Mode
- For Production Mode
String base64 = Base64.encodeToString((“<Username>”+”:”+”<Password>”).getBytes(“UTF-8”), Base64.URL_SAFE|Base64.NO_WRAP);
Note : The authorization field must be Base64 string encoded.