2013-06-03 46 views
2

我正在開發iPhone應用程序,我正在鏈接到本機Twitter應用程序中的特定Twitter推文。我試圖打開Twitter的應用程序是這樣的:在iPhone上打開推文導致404

NSString *stringURL = [NSString stringWithFormat:@"twitter://status?status_id=%i", [self.tweetID intValue] ]; 
NSURL *url = [NSURL URLWithString:stringURL]; 
NSLog(@"Opening Twitter: %@", stringURL); 
[[UIApplication sharedApplication] openURL:url]; 

,但應用程序打開後,它說:「錯誤加載推文(404)」。我驗證了我使用的是與Twitter網站相同的方案(右上角有一個按鈕,它將在iPhone twitter應用程序中打開推文)。點擊twitter網站上的鏈接可以正常工作,所以在我的應用程序中如何進行鏈接時存在一些問題。

我能想到的是,問題發生是因爲我在我的iPhone上處於調試模式,而我的應用程序還沒有發佈或什麼......但這似乎很奇怪。謝謝你的幫助。

回答

1

使用intValue可能會截斷tweetID。試試這個,而不是讓你的stringURL(假設self.tweetID是一個NSString)。

NSString *stringURL = [NSString stringWithFormat:@"twitter://status?status_id=%@", self.tweetID]; 
+0

確切地說,它修復了它。謝謝! –

0

當用戶試圖在有限的時間內多次檢索其Twitter流時,Twitter會顯示錯誤404消息。這被稱爲速率限制。

的URI請求無效或請求的資源,如用戶,不存在等

如果您在使用應用程序,然後嘗試下面的代碼。此代碼在任何條件下只想開Twitter的應用程序無論您是註銷還是登錄到Twitter。

NSString *stringURL = [NSString stringWithFormat:@"twitter://connect?status_id=%i",[self.tweetID intValue]]; 
NSURL *url = [NSURL URLWithString:stringURL]; 
NSLog(@"Opening Twitter: %@", stringURL); 
[[UIApplication sharedApplication] openURL:url]; 
0

Twitter的發帖....檢查出來

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 
    { 


SLComposeViewController *tweetSheet = [SLComposeViewController 
              composeViewControllerForServiceType:SLServiceTypeTwitter]; 

     [tweetSheet setInitialText:@"Great fun to learn iOS programming at appcoda.com!"]; 

     [self presentViewController:tweetSheet animated:YES completion:nil]; 
    } 
+2

這將打開twitter對話框,而不是安裝在你的設備上的twitter應用程序。 – Warewolf

0

你應該試試這個。 這是一個很好的教程來整合FB或/和Twitter,併發布與本機FB/Twitter應用程序的帖子/推文。

http://www.appcoda.com/ios-programming-101-integrate-twitter-and-facebook-sharing-in-ios-6/