English
English
简体中文
Contact Us
Register
Log In
Language
English
English
简体中文
Contact Us
Log In
Register
Go to main website
App Develop

App Development Platform

App development platform provides multiple development methods such as no-code or IoT App SDK development to maximize the monetization of IoT apps.
layoutIndex

Third-party Login System

Last Updated on : 2021-07-16 08:53:34download

The user needs to configure corresponding AppID and AppSecret in the Tuya developer platform > App development > Third-party login. The client shall be developed according to the requirements of all platforms. After the corresponding code is obtained, the relevant login interface of tuyaSDK shall be invoked.

Login on Wechat

Description

Login on Wechat

- (void)loginByWechat:(NSString *)countryCode
				code:(NSString *)code
			success:(nullable TYSuccessHandler)success
			failure:(nullable TYFailureError)failure;

Parameters

Param Description
countryCode Country code, for example: 86
code Code from Wechat authorization login
success Success Callback
failure Failure Callback

Example

Objc:

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

Swift:

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

Login on QQ

Description

Login on QQ

- (void)loginByQQ:(NSString *)countryCode
		userId:(NSString *)userId
	accessToken:(NSString *)accessToken
		success:(nullable TYSuccessHandler)success
		failure:(nullable TYFailureError)failure;

Parameters

Param Description
countryCode Country code, for example: 86
userId User id
accessToken AccessToken from QQ authorization login
success Success Callback
failure Failure Callback

Example

Objc:

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

}

Swift:

func loginByQQ() {
	TuyaSmartUser.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)")
		}
	})
}

Login on Facebook

Description

Login on Facebook

- (void)loginByFacebook:(NSString *)countryCode
				token:(NSString *)token
				success:(nullable TYSuccessHandler)success
				failure:(nullable TYFailureError)failure;

Parameters

Param Description
countryCode Country code, for example: 86
token Token from Facebook authorization login
success Success Callback
failure Failure Callback

Example

Objc:

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

Swift:

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

Login by Twitter

Description

Login by Twitter

- (void)loginByTwitter:(NSString *)countryCode
				key:(NSString *)key
				secret:(NSString *)secret
			success:(nullable TYSuccessHandler)success
			failure:(nullable TYFailureError)failure;

Parameters

Param Description
countryCode Country code, for example: 86
key Key from Twitter authorization login
secret secret from Twitter authorization login
success Success Callback
failure Failure Callback

Example

Objc:

- (void)loginByTwitter {
	[[TuyaSmartUser 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() {
	TuyaSmartUser.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)")
		}
	})
}

Login by Auth2

Description

Auth2 is a general login interface. You can use some auth2 login type by passed type parameters.

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

Parameters

Param Description
type type of Auth2 login(@“ap” for login with apple)
countryCode Country code, for example: 86
accessToken AccessToken
extraInfo Extra info
success Success Callback
failure Failure Callback

Example

Objc:

- (void)loginWithAuth2 {
	[[TuyaSmartUser 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() {
	TuyaSmartUser.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)")
		}
	})
}

Login with Apple

Description

The SDK supports Login with Apple from 3.14.0. After Apple login authorization is successful, information such as token and extraInfo are passed to the SDK through the Auth2 interface.

Parameters

Param Description
type @“ap”
countryCode Country code, for example: 86
accessToken credential.identityToken
extraInfo @{@“userIdentifier”: credential.user, @“email”: credential.email, @“nickname”:credential.fullName.nickname, @“snsNickname”: credential.fullName.nickname}
success Success Callback
failure Failure Callback

Example

Objc:

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

	[[TuyaSmartUser 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
	TuyaSmartUser.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)")
		}
	})
}

Login with Google

Description

The SDK supports Google login from 3.19.0. After authorization is successful, pass in the token (here is google idToken) and extraInfo information through the Auth2 interface to achieve Google login.

Parameters

Param Description
type @“gg”
countryCode Country code, for example: 86
accessToken google authentication idToken ,google authorized id token
extraInfo @{@“pubVersion”: @1}
success Success Callback
failure Failure Callback

Example

Objc:

- (void)loginWithGoogle {

	NSString *loginType = @"gg";    //google login
	NSString *countryCode = @"1";   //USA
	NSString *accessToken = @"id token from google";  // google authorized id token

	[[TuyaSmartUser 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 login
	let countryCode = "1" //USA
	let accessToken = "id token from google" // google authorized id token

	TuyaSmartUser.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)")
			}
		})
}

Login with LINE

Description

The SDK supports LINE login from 3.25.0. After authorization is successful, pass in the token (here is LINE idToken) and extraInfo information through the Auth2 interface to achieve LINE login.

Parameters

Param Description
type @“line”
countryCode Country code, for example: 86
accessToken line authentication idToken ,line authorized id token
extraInfo @{}
success Success Callback
failure Failure Callback

Example

Objc:

- (void)loginWithLine {

	NSString *loginType = @"line";    //line login
	NSString *countryCode = @"1";   //USA
	NSString *accessToken = @"id token from line";  // line authorized id token

	[[TuyaSmartUser 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 login
	let countryCode = "1" //USA
	let accessToken = "id token from line" // line authorized id token

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