PHP Classes

File: qq-sample.php

Recommend this page to a friend!
  Classes of mehmet emin akyüz   QQ   qq-sample.php   Download  
File: qq-sample.php
Role: Example script
Content type: text/plain
Description: a sample script to demonstrate how to connect, authorize and get user information
Class: QQ
Get QQ network user profile using OAuth tokens
Author: By
Last change: remove real appid & appkey
Date: 11 years ago
Size: 1,211 bytes
 

Contents

Class file image Download
<?php
require_once "QQ.php";
session_start();

if( !isset(
$_SESSION['qq'] ) ){
   
$qq = new QQ();
   
$qq->appId = 'yourappid';
   
$qq->appKey = 'yourappkey';
   
$qq->redirectUri = $_SERVER['HTTP_HOST'];

   
$_SESSION['qq'] = $qq;
} else {
   
$qq = $_SESSION['qq'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<?php if( !isset( $_REQUEST['code'] ) && $qq->accessToken == null ){
   
$qqLoginUrl = $qq->getLoginUrl( 'get_user_info,email' );
   
$_SESSION['qq'] = $qq;
?>
<a href="<?=$qqLoginUrl?>">qq login</a>
<?php } else {
    if( !
$qq->userInfo ){
        if(
$qq->getToken() ){
            echo
"Token:" . $qq->accessToken . "<br />";
            if(
$qq->getUser() ){
                echo
"OpenId:" . $qq->openId . "<br />";
?>
<pre style="text-align:left;">
                <?=print_r( $qq->userInfo, true );?>
</pre>
<?php } else {
               
print_r( $qq->error );
            }
        }
    } else {
   
?>
<pre style="text-align:left;">
        <?=print_r( $qq->userInfo, true );?>
</pre>
    <?php
   
}
}
?>

</body>
</html>