Search code examples
oauth-2.0access-tokenpaypal-subscriptions

Unauthorized Error 401 Get OAUTH2 Token for paypal in Angular


I am working on paypal recurring payment and i need token to get subscriber information to allow it login. But i got unauthorized error. Here is my code

getTokan():Observable<any>{

let client_id = '411820721167-jcuj1jeae0l1j06i3q2otsnol2phlqem.apps.googleusercontent.com';
let secret = 'pe7berpzDSlwDVpgj-NQvseP';
let key = client_id+':'+secret;



let headers = new HttpHeaders({
    "Accept": "application/json",
    "Accept-Language": "en_US",
    'Authorization': 'Basic '+key,
    'Content-Type': 'application/x-www-form-urlencoded', 
   });
   let options = { headers: headers };
return this.http.post<any>('https://api.sandbox.paypal.com/v1/oauth2/token',"grant_type=client_credentials", { headers: headers })
}

Explain me what is client id and secret. I am using sandbox client Id secret. i got this error.

zone-evergreen.js:2845 POST https://api.sandbox.paypal.com/v1/oauth2/token 401 (Unauthorized)


Solution

  • That is not a PayPal REST APP's clientId and secret. Get a pair for from the sandbox tab of https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplications

    Also, they must be Base64 encoded in your request