登录 详细集成

1 授权信息页面

显示各个微博平台的授权情况。用户可以新增、更改、删除授权账号。

UINavigationController *accountViewController =[[UMSocialControllerServiceComment defaultControllerService] getSnsAccountController];
[self presentModalViewController:accountViewController animated:YES];

socialbar

2 个人中心页面

上面是绑定一个微博账号作为SDK的登录账号,简称为登录账号,下面是各个已经授权的微博账号,包括我们支持的所有平台,可以对各个平台进行授权和解除授权。

UINavigationController *accountViewController =[[UMSocialControllerServiceComment defaultControllerService] getSocialAccountController];
[self presentModalViewController:accountViewController animated:YES];

socialbar

3 授权页面(界面级接口)

SSO授权

SSO授权即如果用户设备安装了新浪微博客户端,就会跳转到那里进行授权,好处是用户不需要输入用户名和密码,如果没有安装新浪微博客户端的话还会使用webview授权,参看登录快速集成文档对Xcode的设置。下面是用SSO授权到新浪微博:

//`snsName` 代表各个支持云端分享的平台名,有`UMShareToSina`,`UMShareToTencent`等五个。    
  UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
  snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
      NSLog(@"response is %@",response);
  });

这个方法是强制弹出授权,你可以根据已经授权情况来判断是否调用,例如有没有授权到新浪微博

BOOL isOauth = [UMSocialAccountManager isOauthAndTokenNotExpired:UMShareToSina];

网页授权

获得一个授权网页,同样需要加上上面的判断是否已授权。

UINavigationController *oauthController = [[UMSocialControllerService defaultControllerService] getSocialOauthController:UMShareToSina];
[self presentModalViewController:oauthController animated:YES];

socialbar

[UMSocialControllerService defaultControllerService].socialUIDelegate = self;      //设置回调对象
//实现回调方法
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    if (response.viewControllerType == UMSViewControllerOauth) {
        ……
        NSLog(@"didFinishOauthAndGetAccount response is %@",response);
    }
}

4 用户账户相关接口

使用本SDK对个微博平台授权过后,我们提供方法查询用户授权到各个微博平台的信息,例如想获取新浪微博用户的昵称和头像可以用下面的代码。

NSDictionary *snsAccountDic = [UMSocialAccountManager socialAccountDictionary];
UMSocialAccountEntity *sinaAccount = [snsAccountDic valueForKey:UMShareToSina];
UMLog(@"sina nickName is %@, iconURL is %@",sinaAccount.userName,sinaAccount.iconURL);
[UMSocialAccountManager isOauthAndTokenNotExpired:UMShareToSina];
[[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
            NSLog(@"response is %@",response);
        }];
//判断新浪微博账号的token是否有效
    [[UMSocialDataService defaultDataService] requestIsTokenValid:@[UMShareToSina] completion:^(UMSocialResponseEntity *response) {
        NSLog(@"is token valid is %@",[response.data.allValues objectAtIndex:0]);
    }];
//包括各平台的uid和accestoken,各个平台不一样,腾讯微博有openid。得到的数据在回调Block对象形参respone的data属性。    
[[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToTencent  completion:^(UMSocialResponseEntity *response){
            NSLog(@"SnsInformation is %@",response.data);
        }];
[[UMSocialDataService defaultDataService] requestSnsFriends:UMShareToTencent  completion:^(UMSocialResponseEntity *response){
            NSLog(@"SnsFriends is %@",response.data);
        }];
[[UMSocialDataService defaultDataService] requestAddFollow:UMShareToSina followedUsid:@[@"2937537507"] completion:nil];
[UMSocialAccountManager isLoginWithSnsAccount];
[[UMSocialDataService defaultDataService] requestBindToSnsWithType:UMShareToSina completion:nil];
[[UMSocialDataService defaultDataService] requestUnBindToSnsWithCompletion:nil];

常见错误代码含义

错误码 错误原因
503 评论失败
504 获取评论失败