2
按照貝寶開發者的指令「讓你的第一個電話」:使用Ruby路邊寶石訪問貝寶API
curl https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \
-d "grant_type=client_credentials"
這是工作和取得預期的結果,如指令的狀態,但我更喜歡使用Ruby路邊的寶石:
require 'curl'
paypal_result = Curl::Easy.http_post("https://api.sandbox.paypal.com/v1/oauth2/token", "grant_type=client_credentials") do |http|
http.headers['Accept'] = "application/json"
http.headers['Accept-Language'] = "en_US"
http.username = "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp"
end
puts paypal_result.body_str
但是我有以下幾點:
{"error":"invalid_client","error_description":"The basic auth authorization header cannot be decoded"}
這是肯定的錯誤,但WH在我的遏制語法錯了?任何想法?
謝謝喬納森。我使用詳細,我用userpwd替換了用戶名,但它不工作:( – 2013-03-26 10:24:24
您可以使用[paypal-sdk-rest](https://github.com/paypal/rest-api-sdk-ruby)gem簡化你的代碼 – siddick 2013-03-27 16:17:20