IOS 微博 statuses/share 分享接口 图片文字

一,背景

2017-06-26微博公告替换了一些接口,导致以前的:

statuses/repost  //转发一条微博
statuses/update  //发布一条微博
statuses/upload  //上传图片并发布一条微博
statuses/upload  // _url_text 发布一条微博同时指定上传的图片
statuses/destroy   //删除微博

全部替换成新的接口:

statuses/share   //第三方分享链接到微博
问题1:运营配置的安全域名
//这样的一个错误是什么鬼:
Error Domain=ShareSDKErrorDomain Code=204 "(null)" UserInfo={user_data={
error = "text not find domain!";
"error_code" = 10017;
request = "/2/statuses/share.json";
}}
问题原因:在微博申请应用未添加安全域名,看下这里吧
原代码
//发微博响应的方法
-(void)send
{
    NSLog(@"发微博");
    /*
     [https://api.weibo.com/2/statuses/share.json](https://api.weibo.com/2/statuses/share.json)

     access_token    true    string    采用OAuth授权方式为必填参数,OAuth授权后获得。
     status    true    string    用户分享到微博的文本内容,必须做URLencode,内容不超过140个汉字,文本中不能包含“#话题词#”,同时文本中必须包含至少一个第三方分享到微博的网页URL,且该URL只能是该第三方(调用方)绑定域下的URL链接,绑定域在“我的应用 - 应用信息 - 基本应用信息编辑 - 安全域名”里设置。
     pic    false    binary    用户想要分享到微博的图片,仅支持JPEG、GIF、PNG图片,上传图片大小限制为<5M。上传图片时,POST方式提交请求,需要采用multipart/form-data编码方式。
     rip    false    string    开发者上报的操作用户真实IP,形如:211.156.0.1。
     */

    //请求链接
    NSString *urlStr = @"https://api.weibo.com/2/statuses/share.json";
    //1、创建请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    //2、拼接参数
    //从沙盒中获取账号信息
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"access_token"] = [CYAccountTool account].access_token;
    //因为API为分享链接接口 所以文本必须添加自己所设置的安全域名链接  带HTTP协议的
    params[@"status"] = [NSString stringWithFormat:@"%@  http://www.mob.com/",self.textView.text];
    //3、发送请求
    if (self.imageView.subviews.count == 0) {//图片为0时 采用纯文本发送
        [mgrPOST:urlStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
            [MBProgressHUD showSuccess:@"发送成功!!!"];
            //1秒后调用 自动隐藏界面函数
            [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(cancel) userInfo:nil repeats:NO];
        }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [MBProgressHUD showError:@"发送失败!!!"];
        }];
    }else{//图片为有时 采用文本+图片发送
        //设置请求头 发送类型
        [mgr.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
        //发送数据到API
        [mgrPOST:urlStr parameters:params constructingBodyWithBlock:^(id formData) {
                for(NSInteger i=0; i

你可能感兴趣的:(IOS 微博 statuses/share 分享接口 图片文字)