Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource id #2 response from curl php

I'm trying to interpret this command line into curl php

curl command:

curl https://api.sandbox.paypal.com/v1/oauth2/token \
 -H "Accept: application/json" \
 -H "Accept-Language: en_US" \
 -u "{clientId}:{secret}" \
 -d "grant_type=client_credentials"

Here's my curl php code:

$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$info = array(
        'grant_type' =>'client_credentials'
);
 $post_field_string = http_build_query($info, '', '&');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                         
    'Accept-Language: en_US')
); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD,'AQHeHhDPIpAoxWaNkXOwCNFV4cZUobhqDa_4qHPKh0iDrSd6rLaxIknT-lmgwd:EJHLmhBMT9dB48kou4V0jyJzaq-CqUlY0zS6QKsxOZKI15hZHZjTfoSV7MO8we');
curl_setopt($ch, CURLOPT_POSTFIELDS,   $post_field_string );
 curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,1);   
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");    

$exec = curl_exec($ch);
curl_exec($ch);

curl_close($ch);

And I get this result:

Resource id #2

I'm new to curl but I'm trying to study it. Is that the right code in my curl php?

I expect this sample response from curl:

{
  "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-6XR95014BA15863X",
  "expires_in": 28800
}
like image 876
user3391620 Avatar asked Dec 15 '22 22:12

user3391620


1 Answers

Try this code:

CURLOPT_HTTPHEADER is not required if you are passing an array or string.

Added

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); to bypass SSL

<?php
$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$info = array(
        'grant_type' =>'client_credentials'
);
 $post_field_string = http_build_query($info, '', '&');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERPWD,'ATKsMxDPf23rhQTgixcTYxLfuJoBsTiIRyaSQW_4J8_rNoVQsXHQkBjmBN0z:EOvF6RBizzf9qH2eA_s3PYmQk--smR6Xe8kDws228lq5pA0IebXTg902FY7f');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field_string);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,1);   
$exec = curl_exec($ch);
echo '<pre>';
print_r($exec);
curl_close($ch);

Response:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1

PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=234251 Paypal-Debug-Id:976e66d30ed12

SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=138269&TopLevelTxnStartTime=14666662622&Host=slcsbidensectoken502.slc.paypal.com&pid=17346

CORRELATION-ID: 976e66d30ed12

Date: Wed, 04 Jun 2014 10:21:51 GMT

Content-Type: application/json

Transfer-Encoding: chunked

{
    "scope": "openid",
    "access_token": "A015wXWyeWOj3CprA4dz8uvB.AgGUE-A-p6SuQhw..rmGug",
    "token_type": "Bearer",
    "expires_in": 28800
}
like image 148
Vimalnath Avatar answered Jan 09 '23 18:01

Vimalnath