TWRequest是否适用于twitter流API? [英] Does TWRequest work for the twitter streaming api?

查看:116
本文介绍了TWRequest是否适用于twitter流API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个显示附近推文的基本iphone应用。我正在使用TWRequest对象通过twitter搜索API完成此操作。不幸的是,我实际上想要使用他们的GPS坐标在地图上标记推文,并且搜索API似乎没有返回推文的实际位置,其准确性比城市名称更精确。

I am trying to make a basic iphone app that shows nearby tweets. I was using the TWRequest object to accomplish this with the twitter search api. Unfortunately, I would actually like to mark the tweets on a map using their GPS coordinates and the search api doesn't seem to return the actual location that a tweet was made with any better accuracy than the city name.

因此,我认为我需要切换到流式api。我想知道在这种情况下是否可以继续使用TWRequest对象,或者我是否需要切换到使用NSURLConnection?提前致谢!

As such, I think I need to switch to the streaming api. I am wondering if it is possible to continue using the TWRequest object in this case or if I need to actually switch over to using NSURLConnection? Thanks in advance!

Avtar

推荐答案

是的,你可以使用TWRequest对象。使用Twitter API doco中的相应URL和参数创建TWRequest对象,并将TWRequest.account属性设置为Twitter帐户的ACAccount对象。

Yes, you can use a TWRequest object. Create your TWRequest object using the appropriate URL and parameters from the Twitter API doco, and set the TWRequest.account property to the ACAccount object for the Twitter account.

然后您可以使用TWRequest的signedURLRequest方法获取NSURLRequest,可以使用connectionWithRequest创建异步NSURLConnection:。委托:。

You can then use the signedURLRequest method of TWRequest to get an NSURLRequest which can be used to create an asynchronous NSURLConnection using connectionWithRequest:delegate:.

完成后,委托的连接:didReceiveData :只要从Twitter收到数据,就会调用方法。请注意,收到的每个NSData对象可能包含多个JSON对象。在使用NSJSONSerialization从JSON转换每个之前,您需要将它们拆分(用\\\\ n分隔)。

Once this is done, the delegate's connection:didReceiveData: method will be called whenever data is received from Twitter. Note that each NSData object received may contain more than one JSON object. You will need to split these up (separated by "\r\n") before converting each one from JSON using NSJSONSerialization.

这篇关于TWRequest是否适用于twitter流API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆