V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
kobe1941
V2EX  ›  iDev

微博开发,用 AFN 抓取数据时挂了?

  •  
  •   kobe1941 · 2014-04-29 20:53:15 +08:00 · 6430 次点击
    这是一个创建于 3649 天前的主题,其中的信息可能已经有所发展或是发生改变。
    做一个类新浪微博的客户端,抓取数据时,可以获取用户的个人信息,但是在抓取关注的人的微博时返回fail,把错误打印出来,字面上看是权限不够,但是个人觉得应该不会,这是微博公开的接口,求分析。
    以下是代码部分
    NSString *str = [NSString stringWithFormat:@"https://api.weibo.com/2/statuses/friends_timeline.json?access_token=%@",[AccountTool sharedAccountTool].currentAccount.accessToken];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:str]];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

    NSLog(@"成功 %@",JSON);

    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

    NSLog(@"失败--%@--%@--%@",request,response,error);

    }];

    [operation start];
    11 条回复    2014-08-21 11:27:08 +08:00
    kobe1941
        1
    kobe1941  
    OP
       2014-04-29 20:56:25 +08:00
    以下是打印的错误信息,重点在于"error":"Insufficient app permissions!","error_code":10014,权限不够


    失败--<NSURLRequest: 0x8c31b10> { URL: https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.00vWf4GEsE94CD263c7e0837S1eYtC }--<NSHTTPURLResponse: 0x8cd6230> { URL: https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.00vWf4GEsE94CD263c7e0837S1eYtC } { status code: 403, headers {

    "Api-Server-IP" = "10.75.5.57";

    Connection = "keep-alive";

    "Content-Encoding" = gzip;

    "Content-Type" = "application/json;charset=UTF-8";

    Date = "Tue, 29 Apr 2014 12:36:37 GMT";

    Server = "nginx/1.2.0";

    "Transfer-Encoding" = Identity;

    Vary = "Accept-Encoding";

    } }--Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 403" UserInfo=0x8fd2200 {NSLocalizedRecoverySuggestion={"error":"Insufficient app permissions!","error_code":10014,"request":"/2/statuses/friends_timeline.json"}, AFNetworkingOperationFailingURLRequestErrorKey=<NSURLRequest: 0x8c31b10> { URL: https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.00vWf4GEsE94CD263c7e0837S1eYtC }, NSErrorFailingURLKey=https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.00vWf4GEsE94CD263c7e0837S1eYtC, NSLocalizedDescription=Expected status code in (200-299), got 403, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8cd6230> { URL: https://api.weibo.com/2/statuses/friends_timeline.json?access_token=2.00vWf4GEsE94CD263c7e0837S1eYtC } { status code: 403, headers {

    "Api-Server-IP" = "10.75.5.57";

    Connection = "keep-alive";

    "Content-Encoding" = gzip;

    "Content-Type" = "application/json;charset=UTF-8";

    Date = "Tue, 29 Apr 2014 12:36:37 GMT";

    Server = "nginx/1.2.0";

    "Transfer-Encoding" = Identity;

    Vary = "Accept-Encoding";

    } }}
    kobe1941
        2
    kobe1941  
    OP
       2014-04-29 20:59:49 +08:00
    另外比较奇葩的是,我的AFN文件夹拉入工程后,不添加system,security,mobile这几个框架竟然编译可以通过(AFN 的.m文件已加入编译),奇葩啊,会不会是这里出了问题呢?
    txx
        3
    txx  
       2014-04-29 21:46:52 +08:00   ❤️ 1
    1: 為何不用cocoapod 呢....
    2: 為何抓包分析而是要打log呢...
    3: Google 關鍵詞 "weibo 10014"
    ccbikai
        4
    ccbikai  
       2014-04-30 00:26:14 +08:00 via Android   ❤️ 1
    非第三方客户端类appkey无权查看他人微博,开放平台文档看一下
    kobe1941
        5
    kobe1941  
    OP
       2014-04-30 12:53:14 +08:00
    @txx 1.cocoapod 不懂啊,AFN拿来就能用,我已经拿到微博账号的个人信息了,但是拿微博数据时出了问题不知道怎么回事,
    2.用AFN 发送请求,没有返回数据,于是就打印下错误信息
    3.谢谢,我给微博开放平台发私信了,叫我申请高级权限,但明明我调用的接口是普通接口。。。郁闷
    lloydsheng
        6
    lloydsheng  
       2014-04-30 14:23:04 +08:00
    @kobe1941 关于cocoapod,你可以看看我这个帖子
    kobe1941
        7
    kobe1941  
    OP
       2014-04-30 14:43:43 +08:00
    @ccbikai 我目前可以查看已登陆用户的个人信息和关注的人、粉丝,这些都在user栏目下,但是抓取微博数据(在statuses栏目下)全部失败,我找新浪问去,谢谢!
    ccbikai
        8
    ccbikai  
       2014-04-30 19:19:21 +08:00   ❤️ 1
    kobe1941
        9
    kobe1941  
    OP
       2014-04-30 22:33:50 +08:00
    @ccbikai 当前授权就是指登陆用户,我在测试时都是用授权过的账号登陆,然后通过发送包含appkey和response_type=token等请求拿到access_token和uid,再根据access_token和uid来抓取数据的,目前可以访问当前登陆账号个人信息,但是没法得到微博的数据,开始还以为friends_timeline的请求都要转为home_line,后来试了一圈,statuses下的接口(微博接口)都不能访问。希望帮忙分析下,谢谢!

    新浪的文档说明:
    获取自己的微博,参数uid与screen_name可以不填,则自动获取当前登录用户的微博;
    指定获取他人的微博,参数uid与screen_name二者必选其一,且只能选其一;
    接口升级后:uid与screen_name只能为当前授权用户,第三方微博类客户端不受影响;
    读取当前授权用户所有关注人最新微博列表,请使用:获取当前授权用户及其所关注用户的最新微博接口(statuses/home_timeline);
    kobe1941
        10
    kobe1941  
    OP
       2014-05-03 22:53:37 +08:00
    @txx
    @ccbikai 感谢各位回复,问题已经解决,新浪更新了接口没更新文档,客户端只能用先获取code,再用code换取access_token,新创建的应用这样子做授权没问题,接口都可以用.旧应用可以直接response_type=token,但是能不能读取微博接口就看运气了,
    deter3
        11
    deter3  
       2014-08-21 11:27:08 +08:00 via iPad
    @kobe1941 请问这个项目还在做吗? 目前想用的功能。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5661 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 02:27 · PVG 10:27 · LAX 19:27 · JFK 22:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.