我正在为iOS应用程序开发Twitter Feed视图.我找到了TWRequest,它的工作方式与我想要的完全相同.但是:我收到一条通知:"TWRequest已被弃用:首先在iOS 6.0中弃用".我应该用什么呢?
在被授予对该用户帐户的访问权限后,是否有人能够为该用户获取OAuth访问令牌?
twitter提到在iOS文档中使用一个名为"Reverse Auth"的进程,但我似乎无法在其他任何地方找到它.
我感觉有点失落,所以如果任何人可以提供一些内部,将非常感激.
如果iOS用户没有Twitter帐户,是否可以通过TWRequest使用仅应用程序身份验证,例如获取用户的时间线?(user_timeline.json)?
当iOS设备上没有设置Twitter帐户时,我目前正在使用user_timeline.json API获取http状态400.
使用iOS 5的新TWRequestAPI,我遇到了与块使用相关的砖墙.
我需要做的是在收到第一个请求的成功响应后,立即触发另一个请求.在第二个请求的完成块上,然后我通知多步操作的成功或失败.
这大致是我正在做的事情:
- (void)doRequests
{
TWRequest* firstRequest = [self createFirstRequest];
[firstRequest performRequestWithHandler:^(NSData* responseData,
NSHTTPURLResponse* response,
NSError* error) {
// Error handling hidden for the sake of brevity...
TWRequest* secondRequest = [self createSecondRequest];
[secondRequest performRequestWithHandler:^(NSData* a,
NSHTTPURLResponse* b,
NSError* c) {
// Notify of success or failure - never reaches this far
}];
}];
}
Run Code Online (Sandbox Code Playgroud)
我没有保留任何一个请求或在任何地方保留对它们的引用; 这只是一场千载难关.
但是,当我运行应用程序时,它会崩溃EXC_BAD_ACCESS:
[secondRequest performRequestWithHandler:...];
Run Code Online (Sandbox Code Playgroud)
它执行第一个请求就好了,但是当我尝试使用处理程序启动第二个请求时,它会崩溃.这段代码出了什么问题?
创建请求的方法非常简单:
- (TWRequest*)createFirstRequest
{
NSString* target = @"https://api.twitter.com/1/statuses/home_timeline.json";
NSURL* url = [NSURL URLWithString:target];
TWRequest* …Run Code Online (Sandbox Code Playgroud) 使用TWRequest时,Instruments(Leaks)报告内存泄漏,我无法真正看到我做错了什么.
以下是重现问题的步骤:
创建一个新的Xcode项目(禁用ARC),添加Twitter框架,然后将以下行添加到代码中(例如在viewDidLoad中):
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/public_timeline.json"] parameters:nil requestMethod:TWRequestMethodGET];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"in performrequest");
[postRequest release];
}];
Run Code Online (Sandbox Code Playgroud)
在使用Instruments(Leaks)分析此代码之后,它告诉我带有"performRequestWithHandler"的行正在泄漏:


有什么想法可以防止这种泄漏?
我正在使用TWrequest在桌面视图中显示我的推特列表.以下代码有效.问题是更新表格非常慢.我在NSlogging请求响应(发生得非常快),我也循环遍历每个列表并将列表'name'添加到一个数组(再次,很快发生<1s).但由于一些莫名其妙的原因,该表大约需要4秒左右才能更新.
为什么表重新加载需要这么长时间?问题是没有解析响应(因为我可以看到nslog这很快发生),它需要很长时间才能显示在表中?非常感谢帮助!
-(IBAction)getLists{
// First, we need to obtain the account instance for the user's Twitter account
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request permission from the user to access the available Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// The user rejected your request
NSLog(@"User rejected access to the account.");
}
else {
// Grab the available accounts
twitterAccounts = [store accountsWithAccountType:twitterAccountType];
if ([twitterAccounts count] > 0) { …Run Code Online (Sandbox Code Playgroud) - (void)getTwittersFollowers {ACAccountStore*store = [[ACAccountStore alloc] init]; ACAccountType*twitterAccType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
**[store requestAccessToAccountsWithType:twitterAccType withCompletionHandler:^(BOOL granted,NSError *error)**{
if(!granted){
NSLog(@"User refused to access to his account");
}else{
NSArray *twitterAcc=[store accountsWithAccountType:twitterAccType];
if([twitterAcc count]>0){
ACAccount *account=[twitterAcc objectAtIndex:0];
NSLog(@"account name %@",[account accountDescription]);
NSMutableDictionary *params=[[NSMutableDictionary alloc]init];
[params setObject:@"1" forKey:@"inclue_entitles"];
NSURL *url=[NSURL URLWithString:@"http://api.twitter.com/1/followers.json"];
//TWRequest *request=[[TWRequest alloc]initWithURL:url parameters:params requestMethod:TWRequestMethodGET];
SLRequest *request=[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:params];
[request setAccount:account];
[request performRequestWithHandler:^(NSData *responce,NSHTTPURLResponse *urlResponce,NSError *error){
if(!responce){
NSLog(@"%@",error);
}else{
NSError *jsonError;
NSMutableDictionary *followers=[NSJSONSerialization JSONObjectWithData:responce options:NSJSONReadingMutableLeaves error:&error];
if(followers!=nil){
for (int i=0; i<[[followers objectForKey:@"users"] …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用TWRequest对象发布图像.这是我的代码:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSData *pngImage = UIImagePNGRepresentation(image);
NSData *tweetText = [userText copy];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Twitter is good to go");
NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType];
if (twitterAccounts.count) {
ACAccount *twitterAccount = [twitterAccounts objectAtIndex:0];
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:nil requestMethod:TWRequestMethodPOST];
[request addMultiPartData:pngImage withName:@"media" type:@"image/png"];
[request addMultiPartData:tweetText withName:@"text" type:@"text/plain"];
[request setAccount:twitterAccount];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { …Run Code Online (Sandbox Code Playgroud) twrequest ×8
ios ×4
twitter ×4
acaccount ×2
objective-c ×2
cocoa-touch ×1
instruments ×1
ios5 ×1
memory-leaks ×1
uikit ×1
xcode ×1