Recently the project SnapChat third-party login requirements, so I read the development document access. In this process also encountered some small problems, simply record, I hope to help some people

1.SnapChat developers manage the background to create apps

https://kit.snapchat.com/portal/apps, management background can fill in the development and production of some application configuration information To note here is that the Redirect URLs, the first thought is a callback address of the server configuration, but did not give back end should be how to check and use, Finally, it was found that the local URL Scheme information could be used for login authorization, and we obtained the unique user id externalId we needed

2. Configure the development project

Add SnapChat configuration to info.plist

<key>SCSDKClientId</key>
	<string>d8c60733-f2fb-499b-b073-dc3e1c3600c6</string>
	<key>SCSDKRedirectUrl</key>
	<string>tassel://snapLogin</string>
	<key>SCSDKScopes</key>
	<array>
		<string>https://auth.snapchat.com/oauth2/api/user.display_name</string>
		<string>https://auth.snapchat.com/oauth2/api/user.external_id</string>
		<string>https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar</string>
	</array>
Copy the code

3. Start adding the SDK

Note: According to SnapChat's official documentation, SnapChat SDK support is the lowest device version, iOS 10, so if your App is lower than that, you can try to hide it in the lower version for compatibility

This is introduced in Pod mode

pod 'SnapSDK', :subspecs => ['SCSDKLoginKit']
Copy the code

The key code

- (void)snapChatLogin {

    [SCSDKLoginClient loginFromViewController:self completion:^(BOOL success, NSError * _Nullable error) {
        if(success) { [self fetchUserData]; }}]; } - (void)fetchUserData {//"{me{externalId, displayName, bitmoji{avatar}}}";
    [SCSDKLoginClient fetchUserDataWithQuery:queryString variables:nil success:^(NSDictionary * _Nullable resources) {
        NSLog(@"=========> user data %@",resources);
    } failure:^(NSError * _Nullable error, BOOL isUserLoggedOut) {
        
    }];
}
Copy the code

SnapChat SDK supports native APP jump login and web login. The simulator is convenient to use here

Successfully get user information

There is no way to verify the authenticity of externalId at the back end in the Development document of SnapChat. For security reasons, you can consider processing this field

At the end of the Demo, if you encounter or have other ideas during the access process, please feel free to communicate with us