有没有像这样的WordPress 登录 php 脚本?
此脚本用于使用 WordPress.com 帐户登录。
我已按照文档编写脚本。但是当我打印访问令牌时它没有为我提供访问令牌。它表明它是空的。
这是我使用 WordPress.com 帐户实现登录的代码:
session_start();
$client_id = "2472";
$client_secret ="TaB3JPXeuJA8XsosdkMbZnuJoybxJaBF6WmDD11WFJg8QQme9fmye6l2Kxd45cpx";
$login_url = "https://public-api.wordpress.com/oauth2/authorize?client_id=$client_id&redirect_uri=http://w3.softwarecookerbd.com/wordpress.php&response_type=code";
function getToken(){
$curl = curl_init( "https://public-api.wordpress.com/oauth2/token" );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
'client_id' => "2472",
'redirect_uri' => "http://w3.softwarecookerbd.com/wordpress.php",
'client_secret' => "TaB3JPXeuJA8XsosdkMbZnuJoybxJaBF6WmDD11WFJg8QQme9fmye6l2Kxd45cpx",
'code' => $_GET['code'], // The code from the previous request
'grant_type' => 'authorization_code'
) );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$auth = curl_exec( $curl );
$secret = json_decode($auth);
echo "<pre>";
var_dump($secret);
exit;
$access_key = $secret->access_token;
}
if(isset($_GET["code"])&&!empty($_GET["code"])){
//$url = "https://public-api.wordpress.com/oauth2/token?client_id=$client_id&client_secret=client_secret&redirect_uri=http://w3.softwarecookerbd.com/wordpress.php&code=".$_GET['code']."&grant_type=authorization_code";
//$response = file_get_contents($url);
//echo $response;
getToken();
}else{
header("Location: ".$login_url);
}