0
我試圖使用PayPal的紅寶石寶石做一個簡單的任務類似這樣的用戶的PayPal付款:如何:獲取通過PayPal紅寶石寶石
1 - 用戶登錄到使用貝寶的OAuth我的應用程序。
2 - 用戶授權我的應用訪問他的帳戶。
3 - 我的應用程序發出一個簡單的請求,列出此用戶的10個交易。
我以下來自官方PayPal的GitHub的倉庫(https://github.com/paypal/PayPal-Ruby-SDK)
require 'paypal-sdk-rest'
include PayPal::SDK::REST
include PayPal::SDK::OpenIDConnect
# Update client_id, client_secret and redirect_uri
PayPal::SDK.configure({
:openid_client_id => "client_id",
:openid_client_secret => "client_secret",
:openid_redirect_uri => "http://google.com"
})
# Generate URL to Get Authorize code
puts Tokeninfo.authorize_url(:scope => "openid profile")
# Create tokeninfo by using AuthorizeCode from redirect_uri
tokeninfo = Tokeninfo.create("Replace with Authorize Code received on redirect_uri")
puts tokeninfo.to_hash
# Refresh tokeninfo object
tokeninfo = tokeninfo.refresh
puts tokeninfo.to_hash
說明這個簡單的設置代碼後,我試圖讓用戶的交易,但我不能這樣做只是通過付款像下面的代碼實體:
Payment.all(count: 10)
它返回一個錯誤:
PayPal::SDK::Core::Exceptions::UnauthorizedAccess: Failed. Response code = 401. Response message = Unauthorized. Response debug ID = 409003e14dd9a, 409003e14dd9a.
那麼,我該如何驗證用戶進入我的應用程序,然後使用他的令牌來執行API操作?
你確定paypal API支持嗎?可能會試着問他們。 –