IOS 6社交应用开发-新浪微博

原始地址:IOS 6社交应用开发-新浪微博


1.添加Framework.



2.导入头文件.

#import <Accounts/Accounts.h>
#import <Social/Social.h>

3.确保在“设置”里配置了社交应用的帐户(以新浪微博举例),如下图。




 4.获取新浪微博用户.

//获取帐号存储 
    ACAccountStore *strore  = [[ACAccountStore alloc] init];
    //获取新浪微博的帐号类型
    ACAccountType *type = [strore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo];
    //验证是否配置了匹配帐户
    [strore requestAccessToAccountsWithType:type options:nil completion:^(BOOL granted, NSError *error)
    {
        if (granted)//验证授权成功
        {
            //获取新浪微博用户列表
            NSArray *counts = [strore accountsWithAccountType:type];
            if (counts && [counts count] > 0)
            {
                //认证通过
                //以第一个用户举例
                [self requestWithAccount:[counts objectAtIndex:0]];
            }
        }
    }];

5.发布微博.

新浪微博接口文档




- (void)requestWithAccount:(ACAccount *)account
{
    /*
     //类型
     SLServiceTypeTwitter
     SLServiceTypeFacebook
     SLServiceTypeSinaWeibo
     
     //方法
     SLRequestMethodGET
     SLRequestMethodPOST
     SLRequestMethodDELETE
     */
    
    //请求地址,参考上图
    NSURL *url = [NSURL URLWithString:@"https://open.weibo.cn/2/statuses/update"];
    
    //配置参数字典
    NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:@"ssstext", @"status", nil];
    //配置轻取
    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeSinaWeibo requestMethod:SLRequestMethodGET URL:url parameters:para];
    //装载微博用户
    request.account = account;
    //发送微博
    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
    {
        if (!error)
        {
            //主线程中操作UI
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
                NSLog(@"请求结果:%@",response);
                //操作UI
            });
        }
    }];
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值