dqy012345 2013-04-10 10:04
浏览 106

用wordpress登录

Is there any WordPress login php script like this one?

This script is for signing in with WordPress.com account.

I have followed the documentation to write my script. But it did not provide me the access token when I print the access token. It shows it is null.
This is my code to implement sign in with WordPress.com account:

    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);
}
  • 写回答

1条回答 默认 最新

  • duanci1858 2013-04-10 11:40
    关注

    I am not sure about the actual script that you have posted , but there are several plugins that will allow you to do that , you might want to have a look at them, and since they are open-source , if you really want to do it yourself, you can always peep at the code and see what the problem is .

    Some of them that I know (and not limited only to wordpress.com, but to other services as well) are :

    http://wordpress.org/extend/plugins/oa-social-login/

    http://wordpress.org/extend/plugins/socialauth-wp/

    http://wordpress.org/extend/plugins/ssi-sumilux/screenshots/

    And if I am not wrong (maybe i am ) also the wordpress jetpack has this feature ..

    http://wordpress.org/extend/plugins/jetpack/

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog