app微博登录的server

项目背景:

app安卓端的微博登录,php写server;

微博登录:

1、注意,微博登录和微信登录过程略有不同:微博登录在app端授权时,adb(adb logcat -s weibo)中生成的是access token,略过了微信生成code的过程,用于获取用户信息;

2、微博登录有sdk可以直接使用,http://open.weibo.com/wiki/SDK;

3、微博登录php server代码如下:

$appid = "********************";
$secret = "***********************";


$access_token = $_POST["access_token"];
if ($access_token == null) {
    echo "InputParamLack";
    exit();
}
<span style="white-space:pre">	</span>
$weibo = new SaeTClientV2($appid, $secret, $access_token);
$uid_get = $weibo->get_uid();
$uid = $uid_get['uid'];
$user_info = $weibo->show_user_by_id($uid);//根据ID获取用户等基本信息


//根据access_token获取expires_in、refresh_token、scope
$token_info = $weibo->oauth->post("https://api.weibo.com/oauth2/get_token_info", array("access_token" => $access_token));


if (empty($user_info) || empty($access_token)) {
<span style="white-space:pre">	</span>echo "InvalidAccessToken";
<span style="white-space:pre">	</span>exit();
}


//return user info
$return_info = array();
$return_info["openid"] = $user_info["idstr"];
$return_info["nickname"] = $user_info["name"];
$return_info["sex"] = $user_info["gender"] == "m" ? 1 : 0;
$return_info["headimgurl"] = $user_info["profile_image_url"];


用户信息中的idstr字段,相当于微信的openid字段,是唯一性id



参考资料:

http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6 微博官方文档,文档有错误


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值