使用第三方平台账号登录

更新时间:2023-04-17 08:31:57下载pdf

从第三方平台登录前,您需要在 涂鸦 IoT 开发平台第三方接入 页面配置对应的 AppIDAppSecret

然后,您的 App 需要按照各平台要求进行开发,获取到对应的 code 之后,调用智能生活 App SDK 对应的登录接口。

微信登录

接口说明

- (void)loginByWechat:(NSString *)countryCode
                 code:(NSString *)code
              success:(nullable ThingSuccessHandler)success
              failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
countryCode 国家码,例如 86
code 微信授权登录获取的 code
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

建议微信账号登录体系只允许中国大陆的账号,使用国家码 86。对于非中国大陆的账号(即国家码为 86 以外的账号),存在从中国大陆境外访问境内微信服务的可能性,从而可能引发跨境数据传输合规风险。作为数据控制者,您应知晓并承担潜在的跨境数据传输合规风险。

示例代码

Objc:

- (void)loginByWechat {
        [[ThingSmartUser sharedInstance] loginByWechat:@"your_country_code" code:@"wechat_code" success:^{
        NSLog(@"login success");
    } failure:^(NSError *error) {
		NSLog(@"login failure: %@", error);
    }];
}

Swift:

func loginByWechat() {
    ThingSmartUser.sharedInstance()?.login(byWechat: "your_country_code", code: "wechat_code", success: {
        print("login success")
    }, failure: { (error) in
        if let e = error {
            print("login failure: \(e)")
        }
    })
}

QQ 登录

接口说明

- (void)loginByQQ:(NSString *)countryCode
           userId:(NSString *)userId
      accessToken:(NSString *)accessToken
          success:(nullable ThingSuccessHandler)success
          failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
countryCode 国家码,例如 86
userId 用户 ID
accessToken QQ 授权后返回的 accessToken
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

建议 QQ 账号登录体系只允许中国大陆的账号,使用国家码 86。对于非中国大陆的账号(即国家码为 86 以外的账号),存在从中国大陆境外访问境内 QQ 服务的可能性,从而可能引发跨境数据传输合规风险。作为数据控制者,您应知晓并承担潜在的跨境数据传输合规风险。

示例代码

Objc:

- (void)loginByQQ {
    [[ThingSmartUser sharedInstance] loginByQQ:@"your_country_code" userId:@"qq_open_id" accessToken:@"access_token" success:^{
        NSLog(@"login success");
    } failure:^(NSError *error) {
        NSLog(@"login failure: %@", error);
    }];
}

Swift:

 func loginByQQ() {
    ThingSmartUser.sharedInstance()?.login(byQQ: "your_country_code", userId: "qq_open_id", accessToken: "access_token", success: {
        print("login success")
    }, failure: { (error) in
        if let e = error {
            print("login failure: \(e)")
        }
    })
}

Facebook 登录

接口说明

- (void)loginByFacebook:(NSString *)countryCode
                  token:(NSString *)token
                success:(nullable ThingSuccessHandler)success
                failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
countryCode 国家码,例如 86
token Facebook 授权登录获取的 token
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)loginByFacebook {
    [[ThingSmartUser sharedInstance] loginByFacebook:@"your_country_code" token:@"facebook_token" success:^{
        NSLog(@"login success");
    } failure:^(NSError *error) {
        NSLog(@"login failure: %@", error);
    }];
}

Swift:

 func loginByFacebook() {
    ThingSmartUser.sharedInstance()?.login(byFacebook: "your_country_code", token: "facebook_token", success: {
        print("login success")
    }, failure: { (error) in
        if let e = error {
            print("login failure: \(e)")
        }
    })
}

Twitter 登录

接口说明

- (void)loginByTwitter:(NSString *)countryCode
				key:(NSString *)key
				secret:(NSString *)secret
			success:(nullable ThingSuccessHandler)success
			failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
countryCode 国家码,例如 86
key Twitter 授权登录获取的 key
secret Twitter 授权登录获取的 secret
success 接口发送成功回调
failure 接口发送失败回调

示例代码

Objc:


- (void)loginByTwitter {
	[[ThingSmartUser sharedInstance] loginByTwitter:@"your_country_code" key:@"twitter_key" secret:@"twitter_secret" success:^{
		NSLog(@"login success");
	} failure:^(NSError *error) {
		NSLog(@"login failure: %@", error);
	}];

}

Swift:

func loginByTwitter() {
	ThingSmartUser.sharedInstance()?.login(byTwitter: "your_country_code", key: "twitter_key", secret: "twitter_secret", success: {
		print("login success")
	}, failure: { (error) in
		if let e = error {
			print("login failure: \(e)")
		}
	})
}

Auth2 登录

接口说明

Auth2 的接口是一个通用的登录接口,可以根据传参来确认正在使用 Auth2 的类型。

- (void)loginByAuth2WithType:(NSString *)type
                 countryCode:(NSString *)countryCode
                 accessToken:(NSString *)accessToken
                   extraInfo:(NSDictionary *)extraInfo
                     success:(nullable ThingSuccessHandler)success
                     failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
type Auth2 接口调用的类型,例如:如需苹果登录时,设置 “ap”。具体类型包括:
  • wx:微信
  • qq:QQ
  • tw:推特
  • ap:苹果
  • gg:谷歌
  • "":空字符串,表示涂鸦 UID
countryCode 国家码,例如 86
accessToken 授权登录的 token
extraInfo 额外的参数
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)loginWithAuth2 {
	[[ThingSmartUser sharedInstance] loginByAuth2WithType:@"auth2_type" countryCode:@"your_country_code" accessToken:@"auth2_token" extraInfo:@{@"info_key": @"info_value"} success:^{
		NSLog(@"login success");
	} failure:^(NSError *error) {
		NSLog(@"login failure: %@", error);
	}];
}

Swift:

func loginWithAuth2() {
	ThingSmartUser.sharedInstance().loginByAuth2WithType("auth2_type", countryCode: "your_country_code", accessToken: "auth2_token", extraInfo: ["info_key":"info_value"], success: {
		print("login success")
	}, failure: { (error) in
		if let e = error {
				print("login failure: \(e)")
		}
	})
}

苹果登录

接口说明

智能生活 SDK 从 3.14.0 版本开始支持苹果登录。授权成功后,通过 Auth2 的接口传入 tokenextraInfo 等信息,可以实现苹果登录。

参数说明

参数 说明
type @“ap”
countryCode 国家码,例如 86
accessToken [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding]
extraInfo @{@“userIdentifier”: credential.user, @“email”: credential.email, @“nickname”:credential.fullName.nickname, @“snsNickname”: credential.fullName.nickname}
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)loginWithApple {
	ASAuthorizationAppleIDCredential *credential = authorization.credential;

	[[ThingSmartUser sharedInstance] loginByAuth2WithType:@"ap" countryCode:@"your_country_code" accessToken:credential.identityToken extraInfo:{@"userIdentifier": credential.user, @"email": credential.email, @"nickname": credential.fullName.nickname, @"snsNickname": credential.fullName.nickname} success:^{
		NSLog(@"login success");
	} failure:^(NSError *error) {
		NSLog(@"login failure: %@", error);
	}];
}

Swift:

func loginWithApple() {
	let credential = authorization.credential
	ThingSmartUser.sharedInstance().loginByAuth2(withType: "ap", countryCode: "your_country_code", accessToken: credential?.identityToken, extraInfo: 	["userIdentifier": user,"email": email,"nickname": nickname,"snsNickname": nickname], success: {
		print("login success")
	}, failure: { (error) in
		if let e = error {
				print("login failure: \(e)")
		}
	})
}

Google 登录

接口说明

智能生活 SDK 从 3.19.0 版本开始支持 Google 登录。授权成功后,通过 Auth2 的接口传入 token(即 Google idToken)和 extraInfo 等信息,可以实现 Google 登录。

鉴于谷歌在全球网络服务的部署情况,建议中国大陆地区用户避免使用谷歌登录。

参数说明

参数 说明
type @“gg”
countryCode 国家码,例如 86
accessToken Google 授信的 idToken
extraInfo @{@“pubVersion”: @1}
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:

- (void)loginWithGoogle {

    NSString *loginType = @"gg";    //Google 登录
    NSString *countryCode = @"1";   //美国
    NSString *accessToken = @"id token from Google";  // Google 授权的 id token

	[[ThingSmartUser sharedInstance] loginByAuth2WithType:@"gg"
                                             countryCode:countryCode
                                             accessToken:accessToken
                                                extraInfo:@{@"pubVersion": @1}
    success:^{
		NSLog(@"login success");
	} failure:^(NSError *error) {
		NSLog(@"login failure: %@", error);
	}];
}

Swift:

func loginWithGoogle() {

    let loginType = "gg" //Google 登录
    let countryCode = "1" //美国
    let accessToken = "id token from Google" // Google 授权的 id token

    ThingSmartUser.sharedInstance().loginByAuth2(
        withType: "gg",
        countryCode: countryCode,
        accessToken: accessToken,
        extraInfo: [
            "pubVersion": NSNumber(value: 1)
        ],
        success: {
            print("login success")
        },
        failure: { error in
            if let error = error {
                print("login failure: \(error)")
            }
        })
}

LINE 登录

接口说明

智能生活 SDK 从 3.25.0 版本开始支持 LINE 登录。授权成功后,通过 Auth2 的接口传入 token(即 LINE idToken)和 extraInfo 等信息,可以实现 LINE 登录。

鉴于 LINE 在全球网络服务的部署情况,建议中国大陆地区用户避免使用该方式登录。

参数说明

参数 说明
type @“line”
countryCode 国家码,例如 86
accessToken line authentication idToken ,line 授权的id token
extraInfo @{} 传空
success 接口发送成功回调
failure 接口发送失败回调,error 表示失败原因

示例代码

Objc:


- (void)loginWithLine {

    NSString *loginType = @"line";    //LINE 登录
    NSString *countryCode = @"1";   //美国
    NSString *accessToken = @"id token from line";  // line 授权的id token

	[[ThingSmartUser sharedInstance] loginByAuth2WithType:@"line"
                                             countryCode:countryCode
                                             accessToken:accessToken
                                                extraInfo:@{}
    success:^{
		NSLog(@"login success");
	} failure:^(NSError *error) {
		NSLog(@"login failure: %@", error);
	}];
}

Swift:

func loginWithLine() {

    let loginType = "line" //LINE 登录
    let countryCode = "1" //美国
    let accessToken = "id token from line" // LINE 授权的 id token

    ThingSmartUser.sharedInstance().loginByAuth2(
        withType: "line",
        countryCode: countryCode,
        accessToken: accessToken,
        extraInfo: [:],
        success: {
            print("login success")
        },
        failure: { error in
            if let error = error {
                print("login failure: \(error)")
            }
        })
}