版本記錄
| 版本號(hào) | 時(shí)間 |
|---|---|
| V1.0 | 2018.04.04 |
前言
相信很多人用過(guò)友盟,包括友盟的第三方登錄、分享以及統(tǒng)計(jì)。這里我們就分幾個(gè)模塊進(jìn)行詳細(xì)的說(shuō)明 —— 移動(dòng)統(tǒng)計(jì)
(U - App)、網(wǎng)站統(tǒng)計(jì)(U - Web)、消息推送(U - Push)、社會(huì)化分享(U - Share)、游戲統(tǒng)計(jì)(U - Game)、互聯(lián)網(wǎng)運(yùn)營(yíng)數(shù)據(jù)服務(wù)(Dplus)- 多維度、一站式、精細(xì)化數(shù)據(jù)管理服務(wù)。感興趣的可以看上面幾篇。
1. 友盟集成(一) —— UShare模塊之快速集成(一)
2. 友盟集成(二) —— UShare模塊之快速集成(二)
三方登錄的概念
1. 第三方登錄的定義
第三方登錄主要用于簡(jiǎn)化用戶(hù)登錄流程,通過(guò)用戶(hù)擁有的微博、QQ、微信等第三方賬號(hào)進(jìn)行登錄并且構(gòu)建APP自己的登錄賬號(hào)體系。
2. 如何實(shí)現(xiàn)三方登錄
三方登錄所添加的SDK和分享功能相同,在這里不再?gòu)?fù)述,具體工程配置、系統(tǒng)回調(diào)及URL scheme配置參考對(duì)應(yīng)分享文檔即可 分享文檔。
最終通過(guò)調(diào)用登錄接口,獲取用戶(hù)在第三方平臺(tái)的用戶(hù)ID、頭像等資料完成賬號(hào)體系的構(gòu)建。
3. 三方登錄支持的平臺(tái)
- 國(guó)內(nèi)平臺(tái)
微信、QQ、新浪、騰訊微博、人人網(wǎng)、豆瓣
- 國(guó)外平臺(tái)
Facebook、Twitter、linkedIn、Kakao
代碼集成
// 在需要進(jìn)行獲取登錄信息的UIViewController中加入如下代碼
#import <UMShare/UMShare.h>
- (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {
UMSocialUserInfoResponse *resp = result;
// 第三方登錄數(shù)據(jù)(為空表示平臺(tái)未提供)
// 授權(quán)數(shù)據(jù)
NSLog(@" uid: %@", resp.uid);
NSLog(@" openid: %@", resp.openid);
NSLog(@" accessToken: %@", resp.accessToken);
NSLog(@" refreshToken: %@", resp.refreshToken);
NSLog(@" expiration: %@", resp.expiration);
// 用戶(hù)數(shù)據(jù)
NSLog(@" name: %@", resp.name);
NSLog(@" iconurl: %@", resp.iconurl);
NSLog(@" gender: %@", resp.unionGender);
// 第三方平臺(tái)SDK原始數(shù)據(jù)
NSLog(@" originalResponse: %@", resp.originalResponse);
}];
}
舊版本升級(jí)注意
若在4.x及5.x版本中使用微信登錄,升級(jí)后需參考說(shuō)明:4.x/5.x版本升級(jí)(授權(quán)信息變化)
登錄成功后,第三方平臺(tái)會(huì)將用戶(hù)資料傳回,由于各個(gè)平臺(tái)對(duì)于用戶(hù)資料的標(biāo)識(shí)不同,因此為了便于開(kāi)發(fā)者使用,我們將一些常用的字段做了統(tǒng)一封裝,開(kāi)發(fā)者可以直接獲取,不再需要對(duì)不同平臺(tái)的不同字段名做轉(zhuǎn)換,這里列出我們封裝的字段及含義。

不同平臺(tái)的登錄調(diào)用方法
1. 新浪微博:
- 授權(quán)并獲取用戶(hù)信息(獲取uid、access token及用戶(hù)名等)
// 在需要進(jìn)行獲取用戶(hù)信息的UIViewController中加入如下代碼
#import <UMShare/UMShare.h>
- (void)getAuthWithUserInfoFromSina
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Sina currentViewController:nil completion:^(id result, NSError *error) {
if (error) {
} else {
UMSocialUserInfoResponse *resp = result;
// 授權(quán)信息
NSLog(@"Sina uid: %@", resp.uid);
NSLog(@"Sina accessToken: %@", resp.accessToken);
NSLog(@"Sina refreshToken: %@", resp.refreshToken);
NSLog(@"Sina expiration: %@", resp.expiration);
// 用戶(hù)信息
NSLog(@"Sina name: %@", resp.name);
NSLog(@"Sina iconurl: %@", resp.iconurl);
NSLog(@"Sina gender: %@", resp.unionGender);
// 第三方平臺(tái)SDK源數(shù)據(jù)
NSLog(@"Sina originalResponse: %@", resp.originalResponse);
}
}];
}
2. qq:
- 授權(quán)并獲取用戶(hù)信息(獲取uid、access token及用戶(hù)名等)
- (void)getAuthWithUserInfoFromQQ
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:nil completion:^(id result, NSError *error) {
if (error) {
} else {
UMSocialUserInfoResponse *resp = result;
// 授權(quán)信息
NSLog(@"QQ uid: %@", resp.uid);
NSLog(@"QQ openid: %@", resp.openid);
NSLog(@"QQ unionid: %@", resp.unionId);
NSLog(@"QQ accessToken: %@", resp.accessToken);
NSLog(@"QQ expiration: %@", resp.expiration);
// 用戶(hù)信息
NSLog(@"QQ name: %@", resp.name);
NSLog(@"QQ iconurl: %@", resp.iconurl);
NSLog(@"QQ gender: %@", resp.unionGender);
// 第三方平臺(tái)SDK源數(shù)據(jù)
NSLog(@"QQ originalResponse: %@", resp.originalResponse);
}
}];
}
3. 微信:
授權(quán)并獲取用戶(hù)信息(獲取uid、access token及用戶(hù)名等)
注意這里的uid為unionID
// 在需要進(jìn)行獲取用戶(hù)信息的UIViewController中加入如下代碼
#import <UMShare/UMShare.h>
- (void)getAuthWithUserInfoFromWechat
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
if (error) {
} else {
UMSocialUserInfoResponse *resp = result;
// 授權(quán)信息
NSLog(@"Wechat uid: %@", resp.uid);
NSLog(@"Wechat openid: %@", resp.openid);
NSLog(@"Wechat unionid: %@", resp.unionId);
NSLog(@"Wechat accessToken: %@", resp.accessToken);
NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
NSLog(@"Wechat expiration: %@", resp.expiration);
// 用戶(hù)信息
NSLog(@"Wechat name: %@", resp.name);
NSLog(@"Wechat iconurl: %@", resp.iconurl);
NSLog(@"Wechat gender: %@", resp.unionGender);
// 第三方平臺(tái)SDK源數(shù)據(jù)
NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
}
}];
}
4. 騰訊微博
授權(quán)并獲取用戶(hù)信息(獲取uid、access token等)
// 在需要進(jìn)行獲取用戶(hù)信息的UIViewController中加入如下代碼
#import <UMShare/UMShare.h>
- (void)getAuthWithUserInfoFromTencentWeibo
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_TencentWb currentViewController:nil completion:^(id result, NSError *error) {
if (error) {
} else {
UMSocialUserInfoResponse *resp = result;
// 授權(quán)信息
NSLog(@"TencentWeibo uid: %@", resp.uid);
NSLog(@"TencentWeibo accessToken: %@", resp.accessToken);
NSLog(@"TencentWeibo expiration: %@", resp.expiration);
// 第三方平臺(tái)SDK源數(shù)據(jù)
NSLog(@"TencentWeibo originalResponse: %@", resp.originalResponse);
}
}];
}
5. 豆瓣
授權(quán)并獲取用戶(hù)信息(獲取uid、access token等)
// 在需要進(jìn)行獲取用戶(hù)信息的UIViewController中加入如下代碼
#import <UMShare/UMShare.h>
- (void)getAuthWithUserInfoFromDouban
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Douban currentViewController:nil completion:^(id result, NSError *error) {
if (error) {
} else {
UMSocialUserInfoResponse *resp = result;
// 授權(quán)信息
NSLog(@"Douban uid: %@", resp.uid);
NSLog(@"Douban accessToken: %@", resp.accessToken);
NSLog(@"Douban expiration: %@", resp.expiration);
// 第三方平臺(tái)SDK源數(shù)據(jù)
NSLog(@"Douban originalResponse: %@", resp.originalResponse);
}
}];
}
6. 人人
授權(quán)并獲取用戶(hù)信息(獲取uid、access token等)
// 在需要進(jìn)行獲取用戶(hù)信息的UIViewController中加入如下代碼
#import <UMShare/UMShare.h>
- (void)getAuthWithUserInfoFromRenren
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Renren currentViewController:nil completion:^(id result, NSError *error) {
if (error) {
} else {
UMSocialUserInfoResponse *resp = result;
// 授權(quán)信息
NSLog(@"Renren uid: %@", resp.uid);
NSLog(@"Renren accessToken: %@", resp.accessToken);
NSLog(@"Renren expiration: %@", resp.expiration);
// 第三方平臺(tái)SDK源數(shù)據(jù)
NSLog(@"Renren originalResponse: %@", resp.originalResponse);
}
}];
}
后記
本篇主要介紹的就是三方登錄的集成以及代碼示例,感興趣的給個(gè)贊或者關(guān)注~~~~~
