教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php新浪微博登录接口实例代码

php新浪微博登录接口实例代码

发布时间:2016-12-03   编辑:jiaochengji.com
教程集为您提供php新浪微博登录接口实例代码等资源,欢迎您收藏本站,我们将为您提供最新的php新浪微博登录接口实例代码资源
在做微博登陆之前是需要申请到APP KEY 和App Secret ,这个的申请方式请去 open.weibo.com 申请相关内容。

在官网也有相关的开发文档http://open.weibo.com/wiki/可以查看相关资料。
我这里下载的php的SDK直接进行的web网站应用。
下载SDK,配置好config文件。

 

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5345')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5345>

<?php
header('Content-Type: text/html; charset=UTF-8');
 
define( "WB_AKEY" , 'xxxxxxxxxx' );
define( "WB_SKEY" , 'xxxxxxxxxxxxxxxxxxxxxxxxx' );
define( "WB_CALLBACK_URL" , 'http://xxxxxxxxxxxx/callback.php' );//回调地址
*这里的回调地址是指如果用户同意授权,页面跳转至 YOUR_REGISTERED_REDIRECT_URI/?code=CODE     //YOUR_REGISTERED_REDIRECT_URI 就是你的回调地址。
那就第一步需要首先引导用户进行授权。


include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );
 
$o = new SaeTOAuth( WB_AKEY , WB_SKEY );
 
$code_url = $o->getAuthorizeURL( CANVAS_PAGE );
 
echo "<a href=$code_url>授权</a>";


//授权地址为:
 
https://api.weibo.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI</pre>

如果用户同意授权之后,在你的回调地址里需要获取 换取Access Token 来调用接口。获取信息,等等。。。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4835')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4835>
if($_REQUEST['code']){
echo "sds";
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = CANVAS_PAGE;
$tt= new SaeTOAuth( WB_AKEY , WB_SKEY );
$bb = $tt->getAccessToken('code',$keys);
var_dump($bb);
}

在成功获取到AccessToken之后,可以调用saetv2.ex.class.php的一切封装好的函数进行操作,例如,我这里做登陆功能就需要获取用户的信息:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2525')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2525>


/**
* 根据用户UID或昵称获取用户资料
*
* 按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。
* <br />对应API:users/show
*
* @access public
* @param mixed $uid_or_name 用户UID或微博昵称。
* @return array
*/
function show_user( $uid_or_name )
{
return $this->request_with_uid( 'https://api.t.sina.com.cn/users/show.json' , $uid_or_name );
}

您可能感兴趣的文章:
php使用新浪微博API开发用户授权功能
新浪微博如何注销账号?新浪微博注销账号4种方法
PHP实现百度、网易、新浪短网址服务的API接口调用
php新浪微博登录接口实例代码
html5调用app分享功能的介绍
php获取新浪微博数据API的实例代码
php为什么要使用swoole
基于jquery的内容循环滚动小模块(仿新浪微博未登录首页滚动微博显示)
利用php curl实现程序登录新浪微博代码
PHP-Ajax实现异步上传图片到新浪图床

[关闭]
~ ~