一旦用户授权通过,可以使用如下方法获取到用户的社交平台账户信息:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo];
NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType];
Accounts框架支持的社交平台类型ID如下:
NSString * const ACAccountTypeIdentifierTwitter;//Twitter
NSString * const ACAccountTypeIdentifierFacebook;//Facebook
NSString * const ACAccountTypeIdentifierSinaWeibo;//新浪微博
NSString * const ACAccountTypeIdentifierTencentWeibo;//腾讯微博
NSString * const ACAccountTypeIdentifierLinkedIn;//领英
在调用requestAccessToAccountsWithType方法时,可以传入一个字典参数,某些社交平台的授权需要配置一些额外参数,例如:
//facebook相关
NSString * const ACFacebookAppIdKey;//设置appid
NSString * const ACFacebookPermissionsKey;//设置权限key
NSString * const ACFacebookAudienceKey; //权限key
NSString * const ACFacebookAudienceEveryone;//公开权限
NSString * const ACFacebookAudienceFriends;//好友权限
NSString * const ACFacebookAudienceOnlyMe;//私人权限
//领英相关
NSString * const ACLinkedInAppIdKey;//领英appid
NSString * const ACLinkedInPermissionsKey; //设置权限key
//腾讯微博
NSString *const ACTencentWeiboAppIdKey; //设置appid
三、用户信息相关类解析
ACAccount类解析如下:
@interface ACAccount : NSObject
- (instancetype)initWithAccountType:(ACAccountType *)type;//构造方法
@property (readonly, weak, NS_NONATOMIC_IOSONLY) NSString *identifier;//标识符
@property (strong, NS_NONATOMIC_IOSONLY) ACAccountType *accountType;//账户类型
@property (copy, NS_NONATOMIC_IOSONLY) NSString *accountDescription;//账户描述
@property (copy, NS_NONATOMIC_IOSONLY) NSString *username;//用户名
@property (readonly, NS_NONATOMIC_IOSONLY) NSString *userFullName;//完整名称
@property (strong, NS_NONATOMIC_IOSONLY) ACAccountCredential *credential;//授权凭证
@end
ACAccountCredential类解析如下:
@interface ACAccountCredential : NSObject
//构造方法
- (instancetype)initWithOAuthToken:(NSString *)token tokenSecret:(NSString *)secret;
- (instancetype)initWithOAuth2Token:(NSString *)token
refreshToken:(NSString *)refreshToken
expiryDate:(NSDate *)expiryDate;
//token
@property (copy, nonatomic) NSString *oauthToken;
@end
四、ACAccountStore类解析
@interface ACAccountStore : NSObject
//所有账户列表
@property (readonly, weak, NS_NONATOMIC_IOSONLY) NSArray *accounts;
//根据id获取账户
- (ACAccount *)accountWithIdentifier:(NSString *)identifier;
//根据id获取账户类型对象
- (ACAccountType *)accountTypeWithAccountTypeIdentifier:(NSString *)typeIdentifier;
//获取指定类型的所有账户
- (NSArray *)accountsWithAccountType:(ACAccountType *)accountType;
//进行账户存储
- (void)saveAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreSaveCompletionHandler)completionHandler;
//进行账户使用权限申请
- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType
withCompletionHandler:(ACAccountStoreRequestAccessCompletionHandler)handler NS_DEPRECATED(NA, NA, 5_0, 6_0);
- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType
options:(NSDictionary *)options
completion:(ACAccountStoreRequestAccessCompletionHandler)completion;
//如果账户权限已经过期 调用此方法进行刷新
- (void)renewCredentialsForAccount:(ACAccount *)account completion:(ACAccountStoreCredentialRenewalHandler)completionHandler;
//删除账户
- (void)removeAccount:(ACAccount *)account withCompletionHandler:(ACAccountStoreRemoveCompletionHandler)completionHandler;
@end
千里之遥始于足下,冰冻三尺非一日之寒
——共勉