分享到 :

获取用户信息

获取用户信息分为两个步骤:
首先,发送获取用户信息的请求;

[_tencentOAuth getUserInfo])

其中,_tencentOAuth为TencentOAuth类的实例。
其次,实现协议TencentSessionDelegate的获取到用户信息后的回调方法:

//可以通过response获取数据的返回结果
- (void)getUserInfoResponse:(APIResponse*) response;

下面以显示所有信息为例,进行说明:

- (void)getUserInfoResponse:(APIResponse*) response {
    if (URLREQUEST_SUCCEED == response.retCode && kOpenSDKErrorSuccess == response.detailRetCode) {
        NSMutableString *str = [NSMutableString stringWithFormat:@""];
        for (id key in response.jsonResponse) {
            [str appendString: [NSString stringWithFormat: @"%@:%@\n", key, [response.jsonResponse objectForKey:key]]];
        }
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"操作成功" message: [NSString stringWithFormat:@"%@",str] delegate:self cancelButtonTitle:@"我知道啦" otherButtonTitles: nil];
        [alert show];
    } else {
        NSString *errMsg = [NSString stringWithFormat:@"errorMsg:%@\n%@", response.errorMsg, [response.jsonResponse objectForKey:@"msg"]];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"操作失败" message:errMsg delegate:self cancelButtonTitle:@"我知道啦" otherButtonTitles: nil];
        [alert show];
    }
}
返回顶部