Get PayPal token using CURLSMBS

I am trying to use the CURLSMBS plugin in Xojo to get an Access Token from PayPal’s web service. But, I am getting
a 401 “Unauthorized” code instead. I have verified that my ClientID and Secret is correct. Any help would be greatly appreciated.

This is the data returned from the PayPal web server:

ALPN, server did not agree to a protocol
Server certificate:
subject: C=US; ST=California; L=San Jose; O=PayPal, Inc.; OU=PayPal Production;
start date: Aug 21 00:00:00 2018 GMT
expire date: Aug 20 12:00:00 2020 GMT
issuer: C=US; O=DigiCert Inc; CN=DigiCert Global CA G2
SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
POST /v1/oauth2/token HTTP/1.1
Accept: application/json
Accept-Language: en_US
Content-Length: 29
Content-Type: application/x-www-form-urlencoded
upload completely sent off: 29 out of 29 bytes
Mark bundle as not supporting multiuse
HTTP/1.1 401 Unauthorized

Here are the PayPal cURL command lines that I am trying to translate to plugin calls:

curl -v POST \
-H “Accept: application/json” \
-H “Accept-Language: en_US” \
-d “grant_type=client_credentials”

This is my Xojo desktop code:

Var Curl As New CURLSMBS
Var Err As Integer
Var Headers(1) as String
Headers(0) = “Accept: application/json”
Headers(1) = “Accept-Language: en_US”
Curl.SetOptionHTTPHeader Headers

Curl.OptionPassword = ClientID
Curl.OptionUsername = Secret

Curl.CollectDebugData=True ’ For debug purpose
Curl.OptionVerbose=True ’ For debug detailed information
Curl.CollectOutputData = True
Curl.OptionSSLVerifyPeer = 0
Curl.OptionFollowLocation = true
Curl.OptionSSLVerifyHost = 0
Curl.OptionPost = true

Curl.OptionURL = “

Curl.OptionPostFields = “grant_type=client_credentials”



I did see that I had the Password and Username reversed. However, I corrected that and I still get the same server response.

This loos okay.

Did try adding a “User-Agent” header?
Maybe they require it.

Thank you for your suggestion Christian, but could not get it to work.

Feel free to email me a project with real credentials to try myself.

WE fixed it by adding the user agent:

Var Headers(2) As String Headers(0) = "Accept: application/json" Headers(1) = "Accept-Language: en_US" Headers(2) = "User-Agent: curl" Curl.SetOptionHTTPHeader Headers

That is the only difference to using curl on command line.