我正在关注Guide: Integrate Log In with PayPal,试图让它在WordPress 4.7.1上运行。我已成功使用PayPal按钮登录。单击它会带来登录,然后重定向到" returnurl"。
我目前仍在尝试将上一步骤中收到的授权码传递给令牌服务端点以接收访问令牌。
我的" returnurl"有这个卷曲代码(由Guide: grant token from authorization code建议):
<?php
$curl = curl_init( 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice' );
// not $curl = curl_init( 'https://api.sandbox.paypal.com/v1/oauth2/token' );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$code = $_GET['code']; // The code from the previous request
$redirect_uri = 'http://xxxxxx.contemplate.me.ke/';
curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
'redirect_uri' => $redirect_uri,
'grant_type' => 'authorization_code',
'code' => $code
) );
curl_setopt( $curl, CURLOPT_USERPWD,
"My-Client-Id" . ":" .
"My-Secret");
$auth = curl_exec( $curl );
print '$auth = ';print_r($auth); // to see the error
$secret = json_decode($auth);
$access_key = $secret->access_token;
?>
登录后我得到的是:
$auth = {"error_description":"Grant type is null","error":"invalid_grant","correlation_id":"0f5787fc6413f","information_link":"https://developer.paypal.com/docs/api/#errors"}
我做错了什么?