我試圖從PayPal APIs Getting Started Guide適應的例子PHP:API憑據不正確
<?php
define('PAYPAL_API_USER', '<snip>');
define('PAYPAL_API_PWD', '<snip>');
define('PAYPAL_API_SIGNATURE', '<snip>');
define('PAYPAL_API_APPLICATION_ID', 'APP-80W284485P519543T');
$endpoing = 'https://svcs.sandbox.paypal.com/AdaptiveAccounts/CreateAccount';
$headers = array(
'X-PAYPAL-SECURITY-USERID' => PAYPAL_API_USER,
'X-PAYPAL-SECURITY-PASSWORD' => PAYPAL_API_PWD,
'X-PAYPAL-SECURITY-SIGNATURE' => PAYPAL_API_SIGNATURE,
'X-PAYPAL-REQUEST-DATA-FORMAT' => 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT' => 'JSON',
'X-PAYPAL-APPLICATION-ID' => PAYPAL_API_APPLICATION_ID,
'X-PAYPAL-DEVICE-IPADDRESS' => '192.0.2.0', // :-? Also tried with my public IP address
'X-PAYPAL-SANDBOX-EMAIL-ADDRESS' => '<snip>', // Typed my account's e-mail
);
$payload = '{
"sandboxEmailAddress": "Sender-emailAddress",
"accountType": "PERSONAL",
"name": {
"firstName": "Lenny",
"lastName": "Riceman"
},
"address": {
"line1": "123 Main St",
"city": "Austin",
"state": "TX",
"postalCode": "78759",
"countryCode": "US"
},
"citizenshipCountryCode": "US",
"contactPhoneNumber": "512-555-5555",
"dateOfBirth": "1968-01-01Z",
"createAccountWebOptions": {
"returnUrl": "http://www.example.com/success.html"
},
"currencyCode": "USD",
"emailAddress": "[email protected]",
"preferredLanguageCode": "en_US",
"registrationType": "Web",
"requestEnvelope": {
"errorLanguage": "en_US"
}
}';
$options = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => false,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
);
try{
$curl = curl_init($endpoing);
if(!$curl){
throw new Exception('Could not initialize curl');
}
if(!curl_setopt_array($curl, $options)){
throw new Exception('Curl error:' . curl_error($curl));
}
$result = curl_exec($curl);
if(!$result){
throw new Exception('Curl error:' . curl_error($curl));
}
curl_close($curl);
echo $result;
}catch(Exception $e){
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
}
...但我總是把它恢復:
<?xml version='1.0' encoding='utf-8'?>
<ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/aa">
<responseEnvelope>
<timestamp>2013-03-20T16:33:46.309-07:00</timestamp>
<ack>Failure</ack>
<correlationId>7d7fa53e6a930</correlationId>
<build>5343121</build>
</responseEnvelope>
<error>
<errorId>520003</errorId>
<domain>PLATFORM</domain>
<subdomain>Application</subdomain>
<severity>Error</severity>
<category>Application</category>
<message>Authentication failed. API credentials are incorrect.</message>
</error>
</ns3:FaultMessage>
我再次檢查API憑證(用戶,通行證和簽名),並且它們完全與配置文件頁面中顯示的一樣。我不完全確定X-PAYPAL-DEVICE-IPADDRESS
和X-PAYPAL-SANDBOX-EMAIL-ADDRESS
。
我懷疑我誤讀了一些東西或省略了一些捲曲選項。你能發現我的代碼有什麼問題嗎?
是的,當然......我必須失明!這就解釋了爲什麼我得到的是XML錯誤消息而不是JSON。非常感謝你。 – 2013-03-21 08:18:30
解決這個問題後,我仍然得到了相同的錯誤信息(除了JSON格式很好)。最後,我從PayPal.com下載了一些PHP樣本,這些樣本碰巧有一個配置文件,上帝知道誰是API憑證。我嘗試了這些,並開始工作。所以,出於某種原因,PayPal已經爲我分配了一個無效的API密碼。 (但是,當然,我愚蠢的捲曲錯誤是我的代碼中的明顯問題。) – 2013-03-21 21:24:17
大家好,我有身份驗證失敗的錯誤。我從貝寶網站獲得了API。我在開發人員站點中創建了沙箱帳戶。我也檢查了標題。但我無法解決這個錯誤。請給我建議。 – user2003356 2013-09-02 07:29:09