# 开通

  • 注册Facebook账号
  • 登录Facebook开发者中心,打开“我的应用”页面
  • 点击“创建应用”,根据提示填写应用信息
  • 创建应用完成后即可获得应用编号(AppID)
  • 进入应用详情页面,为应用添加登录功能,并配置Android/iOS平台信息

更多信息详见 申请开通Facebook登录操作指南

# 配置

  • appid Facebook开发者中心申请的应用编号(AppID)

Notice

  • The standard real machine running base in HBuilderX uses the AppID and other information that DCloud applies for the HBuilder application, which is only used to experience the Facebook login function
  • The configuration parameters need to be submitted to the cloud to be packaged to take effect. Please use the [custom debugging base] when the real machine is running (https://ask.dcloud.net.cn/article/35115)

# 使用Facebook登录

# 示例代码

  • uni-app项目
uni.login({
    provider: 'facebook',
    success: function (loginRes) {
        // login successful
        uni.getUserInfo({
            provider: 'facebook',
            success: function(info) {
                // Obtain user information successfully, info.authResult saves user information
            }
        })
    },
    fail: function (err) {
        // 登录授权失败
        // err.code is the error code
    }
});
  • 5+ App项目
var facebookOauth = null;
plus.oauth.getServices(function(services) {
	for (var i in services) {
		var service = services[i];
        // 获取facebook登录对象
		if (service.id == 'facebook') {
			facebookOauth = service;
			break;
		}
	}
	facebookOauth.login( function(oauth){
		// 授权成功,facebookOauth.authResult 中保存授权信息
	}, function(err) {
    // 登录授权失败
    // err.code is the error code
	})
}, function(err) {
	// Failed to get services
})