Beispiel #1
0
        $exit = true;
    } else {
        if (isset($_GET['code'])) {
            //从Callback返回时
            if (OpenSDK_RenRen_SNS2::getAccessToken('code', array('code' => $_GET['code'], 'redirect_uri' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']))) {
                $uinfo = OpenSDK_RenRen_SNS2::call('friends.get');
                echo '从Opent返回并获得授权。你的人人帐号信息为:<br />';
                echo 'Access token: ', OpenSDK_RenRen_SNS2::getParam(OpenSDK_RenRen_SNS2::ACCESS_TOKEN), '<br />';
                echo 'Refresh token: ', OpenSDK_RenRen_SNS2::getParam(OpenSDK_RenRen_SNS2::REFRESH_TOKEN), '<br />';
                echo 'Expire in:', OpenSDK_RenRen_SNS2::getParam(OpenSDK_RenRen_SNS2::EXPIRES_IN), '<br />';
                echo 'Uid:', OpenSDK_RenRen_SNS2::getParam(OpenSDK_RenRen_SNS2::OAUTH_USER_ID), '<br />';
                echo '你的人人好友:<br /><pre>';
                var_dump($uinfo);
            } else {
                echo '获得Access Tokn 失败';
            }
            $exit = true;
        } else {
            if (isset($_GET['go_oauth'])) {
                $callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                $url = OpenSDK_RenRen_SNS2::getAuthorizeURL($callback, 'code', 'state');
                header('Location: ' . $url);
            } else {
                echo '人人OAuth2.0接口演示<a href="?go_oauth">点击去授权</a>';
            }
        }
    }
}
if ($exit) {
    echo '<a href="?exit">退出再来一次</a>';
}
Beispiel #2
0
 /**
  * 获得OAuth2 对象
  * @return OpenSDK_OAuth2_Client
  */
 protected static function getOAuth()
 {
     if (null === self::$oauth) {
         self::$oauth = new OpenSDK_OAuth2_Client(self::$_debug);
     }
     return self::$oauth;
 }