2016-03-25 14 views
0

Ben yeni bir erişim jetonu almak üzere Paypal için bir istek yapmaya çalışıyorum, ancak basit bir bukle çağrısı çalışırken, bu hata ile dönüyor -PayPal - Geçersiz arayan, CLIENT_ID & sır gerektirir

"Invalid_request - Geçersiz arayan, client_id & gizli "

gerektirir. Bunun nesi yanlış? Müşteri kimliği ve sırrı doğru ve dahil edilmiştir.

   $clientId = "XXX"; 
       $secret = "XXX"; 
       $url = "https://api.sandbox.paypal.com/v1/oauth2/token"; 
       $method = 'POST'; 
       $postvals = sprintf("client_id=%s&client_secret=%s&grant_type=%s&refresh_token=%s", 
          $clientId, 
          $secret, 
          'refresh_token', 
          $refreshToken); 


       $ch = curl_init($url); 

       if ($method == 'POST'){ 
        $options = array(
         CURLOPT_POST => 1, 
         CURLOPT_POSTFIELDS => $postvals, 
        ); 
        curl_setopt_array($ch, $options); 
       } 

       curl_setopt($ch, CURLOPT_URL, $url); 
       curl_setopt($ch, CURLOPT_HEADER, true); 
       curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
       curl_setopt($ch, CURLOPT_SSLVERSION, 1); 
       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
       curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret); 
       curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
       curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
       curl_setopt($ch, CURLOPT_VERBOSE, true); 
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
       curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Accept: application/json", 
        "Accept-Language: en_US", 
        "Content-Type: application/x-www-form-urlencoded", 
        'Authorization: Bearer '.$old_accessToken, 
        "Host: www.paypal.com", 
        "Connection: close" 
       ) 
       ); 

       $result = curl_exec($ch); 

       // Get Request and Response Headers 
       $requestHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT); 
       $responseHeaderSize = strlen($result) - curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD); 
       $responseHeaders = substr($result, 0, $responseHeaderSize); 

       //only use body and not header, otherwise return is NULL 
       $result = substr($result, $responseHeaderSize); 

       if(!$result || empty($result)){ 
        echo 'Curl error or response is empty: ' . curl_error($ch); 
        curl_close($ch); 
       } else { 
        curl_close($ch); 
        $response =json_decode($result); 
        var_dump($response); 
       } 

cevap

0

Bu çözüm yerine çalıştı - - İşte

denedim budur

$clientId = "XXXX"; 
    $clientSecret = "XXXX"; 
    $url = "https://api.sandbox.paypal.com/v1/oauth2/token"; 
    $method = 'POST'; 
    $postdata = sprintf("client_id=%s&client_secret=%s&grant_type=%s&refresh_token=%s", 
           $clientId, 
           $secret, 
           'refresh_token', 
           $refreshToken); 

    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_USERPWD, $clientId . ":" . $clientSecret); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 
    # curl_setopt($curl, CURLOPT_VERBOSE, TRUE); 
    $response = curl_exec($curl); 
      if (empty($response)) { 
       // some kind of an error happened 
       die(curl_error($curl)); 
       curl_close($curl); // close cURL handler 
      } else { 
       $info = curl_getinfo($curl); 
       echo "Time took: " . $info['total_time']*1000 . "ms\n"; 
       curl_close($curl); // close cURL handler 
       if($info['http_code'] != 200 && $info['http_code'] != 201 ) { 
        echo "Received error: " . $info['http_code']. "\n"; 
        echo "Raw response:".$response."\n"; 
        die(); 
       } 
      } 
    // Convert the result from JSON format to a PHP array 
    $jsonResponse = json_decode($response);