2012-01-19 109 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令牌過期多久? –

相關問題