2012-01-19 81 views
0

我的应用程序可以在一个月前将数据(图片和文本)发布到Twitter。但现在,它不能发布数据到twitter。告诉我为什么?按照无法从我的应用程序发布数据到Twitter?

Error: [Whoa there! The request token for this page is invalid. It may have already been used, or expired because it it too old. Please go back to the site or application that sent you here and try again; it was probably jusst a mistake]

有了这个消息,我无法确认: 1.已经被使用:当它的这个错误? 2.过期,因为它太旧了:twitter已经过期了令牌?如何重新开放过期? =>这个错误的解决方案是什么?谢谢!

+1

我使用MGTwitterEngine –

+1

我在解决方案http://www.musicalgeometry.com/?p=1537找到。谢谢 –

回答

0

如果您正在使用ios 5,那么下面的代码会有帮助,因为我通过此代码发送图像和文本。

首先是添加框架“twitter.framework”

NSString *var = txtTwitter.text; 
    NSString *str = [[NSUserDefaults standardUserDefaults]valueForKey:@"INDEX"]; 


    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

    // Create an account type that ensures Twitter accounts are retrieved. 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

    // Request access from the user to use their Twitter accounts. 
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { 
     if(granted) { 
      // Get the list of Twitter accounts. 
      NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; 


      if ([accountsArray count] > 0) { 

       ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; 

       TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST]; 

       //add text 
       [postRequest addMultiPartData:[var dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"]; 

       UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"00%@.jpg",str]]; 

       //add image 
       [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/form-data"]; 

       // Set the account used to post the tweet. 
       [postRequest setAccount:twitterAccount]; 

       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
        NSLog(@"Twitter msg %@",output); 
        //      [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO]; 
       }]; 
      } 
     } 
    }]; 
+0

谢谢!我必须使用MGTwitterEngine,因为我的应用程序在iOS 4,5 –

0

错误可能是因为您的请求令牌已经过期了。 您需要重新生成您的访问令牌。

转到https://dev.twitter.com/并单击重新创建访问令牌。

+0

上开个玩笑谢谢!但是这个解决方案,我必须再次编译我的应用程序,因为这个参数包含在应用程序的代码中 –

+0

是的,您需要重新编译您的应用程序。由于这些令牌非常机密,因此twitter会在某段时间内过期令牌。 – vikiiii

+0

如果twitter在某段时间内令牌失效,如何开发苹果市场的商业应用? twitter令牌过期多久? –

相关问题