项目背景:
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"];
参考资料:
http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6 微博官方文档,文档有错误