API 凭据与 paypal_permissions gem 不正确
Posted
技术标签:
【中文标题】API 凭据与 paypal_permissions gem 不正确【英文标题】:API credentials are incorrect with paypal_permissions gem 【发布时间】:2012-09-19 04:53:16 【问题描述】:我正在使用https://github.com/moshbit/paypal_permissions 获取我的应用的卖家权限。
所有方法都工作正常,但是当我尝试使用方法 get_basic_personal_data
和 get_advanced_personal_data
时,我在日志中得到了这个响应:
:raw_response=>"responseEnvelope.timestamp=2012-09-27T04%3A36%3A17.904-07%3A00&response
Envelope.ack=Failure&responseEnvelope.correlationId=3baaaa7435436&responseEnvelope.build
=2210301&error(0).errorId=520003&error(0).domain=PLATFORM&error
(0).subdomain=Application&error(0).severity=Error&error(0).category=Application&error
(0).message=Authentication+failed.+API+credentials+are+incorrect.", :errors=>
[:parameters=>[], :error_id=>"520003", :domain=>"PLATFORM", :subdomain=>"Application",
:severity=>"Error", :category=>"Application", :message=>"Authentication failed. API
credentials are incorrect."], :personal_data=>,
:timestamp=>"2012-09-27T04:36:17.904-07:00", :ack=>"Failure", :correlation_id=>"3baaaa7435436"
你可以在https://github.com/moshbit/paypal_permissions/blob/master/examples/app/controllers/merchants_controller.rb看到这些方法
这是我users_controller.rb
中的3个方法+最后的方法get_basic_personal_data
:
def request_permissions_callback
callback_url = URI.encode(response_permissions_callback_user_url(current_user))
permissions = 'REFUND, ACCESS_BASIC_PERSONAL_DATA'
paypal_response = ::PAYPAL_PERMISSIONS_GATEWAY.request_permissions callback_url, permissions
if paypal_response[:ack] == 'Success'
session[:id] = current_user.id
request_token = paypal_response[:token]
session[:request_token] = request_token
url = ::PAYPAL_PERMISSIONS_GATEWAY.redirect_user_to_paypal_url(request_token)
redirect_to url
else
#render :text => paypal_response.inspect
# handle error
format.html redirect_to requirements_to_sell_user_path(current_user), alert: t(".permissions_wrong")
end
end
def response_permissions_callback
session[:request_token_verifier] = params[:verification_code]
get_access_token
logger.info get_basic_personal_data(current_user).inspect
p get_basic_personal_data(current_user).inspect
respond_to do |format|
if get_access_token == true
format.html redirect_to requirements_to_sell_user_path(current_user), notice: t(".refund_permissions_success")
elsif get_access_token == false
format.html redirect_to requirements_to_sell_user_path(current_user), alert: t(".refund_permissions_wrong")
end
end
end
def get_access_token
request_token = session[:request_token]
verifier = session[:request_token_verifier]
paypal_response = ::PAYPAL_PERMISSIONS_GATEWAY.get_access_token request_token, verifier
if paypal_response[:ack] == 'Success'
current_user.update_attributes(
:ppp_access_token => paypal_response[:token],
:ppp_access_token_verifier => paypal_response[:token_secret],
)
return true
else
return false
end
end
def get_basic_personal_data(current_user)
access_token = current_user.ppp_access_token
verifier = current_user.ppp_access_token_verifier
::PAYPAL_PERMISSIONS_GATEWAY.get_basic_personal_data(access_token, verifier)
end
request_permissions_callback
(向 paypal 发出请求,用户被重定向到 paypal 权限页面。)
response_permissions_callback
收到来自 paypal 的响应,并调用 get_access_token
更新我的 mongodb 数据库中的数据。
当卖家使用
从贝宝权限帐户返回时,我收到错误日志logger.info get_basic_personal_data(current_user).inspect
get_access_token
被触发后,我可以在我的数据库中看到在 get_basic_personal_data
方法上使用后的正确令牌:
ppp_access_token: "ZlM-jt4LQUxQZDozxkH29I53QyXShtziJIbPlCk3m35i65iLiqVf7w", ppp_access_token_verifier: "wJd3uuP5ymyWAqiUf2qaVCPTMsk"
如果其他 3 种方法工作正常且 api 凭据正确,为什么我在此方法中出现此错误?,错误在哪里?
非常感谢!
【问题讨论】:
【参考方案1】:感谢 Mark 的帮助:D。
错误出现在我的development.rb
文件中。
您可以评论或删除ActiveMerchant::Billing::Base.mode = :test
行,现在工作正常。
Myapp::Application.configure do
config.after_initialize do
#ActiveMerchant::Billing::Base.mode = :test
permissions_options =
:login => 'myapp_api1.gmail.com',
:password => 'mypassword',
:signature => 'mysignature',
:app_id => 'APP-80W284485P519543T', # This is the app_id for all PayPal Permissions Service sandbox test
apps
::PAYPAL_PERMISSIONS_GATEWAY = ActiveMerchant::Billing::PaypalPermissionsGateway.new(permissions_options)
end
end
非常感谢!
【讨论】:
以上是关于API 凭据与 paypal_permissions gem 不正确的主要内容,如果未能解决你的问题,请参考以下文章
Dynamics CRM 2016 Online Rest API 与客户端凭据 OAuth 流