【发布时间】:2017-06-04 12:49:45
【问题描述】:
我正在关注Guide: Integrate Log In with PayPal,试图让它在 WordPress 4.7.1 上运行。我已成功嵌入使用 PayPal 登录按钮。点击它带来登录,然后重定向到“returnurl”。
我目前正试图将在上一步中收到的授权代码传递给 tokenservice 端点以接收访问令牌。
我的“returnurl”有这个 curl 代码(由 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"}
我做错了什么?
【问题讨论】:
标签: php wordpress curl paypal login