Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get request for my Paypal AccessToken

I am trying to get my access token of paypal.

I have the next parameters: EndPoint, Client Id, secret, api username, api signature, api password, application Id.

should I need a paypal client in order to do it?

I followed this link: https://developer.paypal.com/docs/integration/direct/make-your-first-call/

and tried:

private string getAccessToken() {
    var ppClient; // = new paypalClient(); // create a paypal client

    Dictionary<string, object> parameters = new Dictionary<string, object>();

    parameters.Add("Accept", "application/json");
    parameters.Add("Accept-Language", "en_US");
    parameters.Add("grant_type", "client_credentials");

    var result = ppClient.Get("https://api.sandbox.paypal.com/v1/oauth2/token", parameters);

    string accessToken = result["access_token"];
    return accessToken;
}

thank you all!

like image 464
Maor Cohen Avatar asked Oct 02 '22 22:10

Maor Cohen


1 Answers

I would recomend using RestSharp (just grab the NuGet package): -

        if (ServicePointManager.SecurityProtocol != SecurityProtocolType.Tls12) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // forced to modern day SSL protocols
        var client = new RestClient(payPalUrl) { Encoding = Encoding.UTF8 };
        var authRequest = new RestRequest("oauth2/token", Method.POST) {RequestFormat = DataFormat.Json};
        client.Authenticator = new HttpBasicAuthenticator(clientId, secret);
        authRequest.AddParameter("grant_type","client_credentials");
        var authResponse = client.Execute(authRequest);
like image 63
Cueball 6118 Avatar answered Oct 05 '22 13:10

Cueball 6118