X灬X
X灬X
  • 发布:2016-06-20 11:58
  • 更新:2017-08-30 08:49
  • 阅读:4426

请问第三方登录如何获取openid

分类:MUI
mui
var auth = auths[this.authId];  
								var waiting = plus.nativeUI.showWaiting();  
								auth.login(function() {  
									waiting.close();  
									plus.nativeUI.toast("登录认证成功");  
									auth.getUserInfo(function() {  
										plus.nativeUI.toast("获取用户信息成功");  
										var name = auth.userInfo.nickname || auth.userInfo.name;  
										app.createState(name, function() {  
											toMain();  
										});  
									}, function(e) {  
										plus.nativeUI.toast("获取用户信息失败:" + e.message);  
									});  
								}, function(e) {  
									waiting.close();  
									plus.nativeUI.toast("登录认证失败:" + e.message);  
								});

请问如何获取openid,userinfo里面只有一个nickname吗?

2016-06-20 11:58 1 条评论 负责人:无 分享
已邀请:
X灬X

X灬X (作者)

我自己试着弄了下 搞出来了

auth.getUserInfo(function(authResult) {  
	plus.nativeUI.toast("获取用户信息成功");  
	var name = auth.userInfo.nickname || auth.userInfo.name;  
	app.createState(name, function() {  
//		console.log(JSON.stringify(authResult));  
		var openid = authResult.target.authResult.openid;
z***@21cn.com

z***@21cn.com

我正好也遇到这个问题,同问

asmallbird

asmallbird

interface plus.oauth.AuthService {
// Attributes
attribute String id;
attribute String description;
attribute AuthInfo authResult;
attribute UserInfo userInfo;
attribute JSON extra;

// Methods  
function void login( successCallback, errorCallback, options );  
function void logout( successCallback, errorCallback );  
function void getUserInfo( successCallback, errorCallback );  
function void addPhoneNumber( successCallback, errorCallback );  

}

interface plus.oauth.AuthInfo {
attribute String openid;
attribute String access_token;
attribute String expires_in:
attribute String refresh_token;
attribute String scope;
}

openid是AuthInfo 的一个属性,而AuthInfo是AuthService中的authResult返回值,也就是说用

AuthService.authResult.openid就可以获得openid,注意AuthService要通过第一步获取到具体的服务对象,这里我只是写了伪代码

该问题目前已经被锁定, 无法添加新回复