新浪微博php sdk之yii framework扩展

看到yii官网没有新浪微博扩展,想想难道不大,自己写个yii扩展吧
已经上传到官网http://www.yiiframework.com/extension/sina-weibo-sdk/
使用说明:
1.下载资源文件,申请app key
2.文件放到相应的extensions和controlers目录下
3.修改扩展文件夹下的config文件,填写自己申请的app key

Yii::import('ext.sinaWeibo.SinaWeibo',true);
class WeiboController extends Controller
{
public function actionIndex(){
$weiboService=new SinaWeibo(WB_AKEY, WB_SKEY);
$code_url = $weiboService->getAuthorizeURL( WB_CALLBACK_URL );
$_SESSION['back_url']=$this->createUrl('weibolist');
echo '<a href="'.$code_url.'">授权</a>';
}
public function actionCallback(){
$weiboService=new SinaWeibo(WB_AKEY, WB_SKEY);
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = WB_CALLBACK_URL;
try {
$token = $weiboService->getAccessToken( 'code', $keys ) ;
} catch (OAuthException $e) {
}
}
if ($token) {
$_SESSION['token'] = $token;
setcookie( 'weibojs_'.$weiboService->client_id, http_build_query($token) );
header( "refresh:3;url=".$_SESSION[back_url]);
echo "<h1>认证已经通过,将会在3秒之后跳转到微博列表页面。如果没有,点击<a href=".$_SESSION['back_url'].">这里</a>。</h1>";exit;
} else {
echo '认证失败';
}
}
public function actionWeibolist(){
$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$ms = $c->home_timeline(); // done
var_dump($ms);exit;
$uid_get = $c->get_uid();
$uid = $uid_get['uid'];
$user_message = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息
}
}

 

发布日期:
分类:Yii

发表评论

邮箱地址不会被公开。 必填项已用*标注