2011-02-24 105 views
0

我使用這個代碼小塊在Twitter上張貼張貼到Twitter,與真正的憑據到位「mytwitterloginname」和「mytwitterpassword」佔位符:無法從我的iPhone應用程序

void _StartTwitter() 
{ 

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: 
            [NSURL URLWithString:@"http://mytwitterloginname:[email protected]/statuses/update.xml"] 
                  cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 

    // The text to post 
    NSString *msg = @"testing"; 

    // Set the HTTP request method 
    [request setHTTPMethod:@"POST"]; 

    [request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg] 
          dataUsingEncoding:NSASCIIStringEncoding]]; 

    NSURLResponse *response; 
    NSError *error; 

    if ([NSURLConnection sendSynchronousRequest:request 
           returningResponse:&response error:&error] != nil) 
     NSLog(@"Posted to Twitter successfully."); 
     else 
      NSLog(@"Error posting to Twitter."); 
} 

但即使我的控制檯說這個帖子是成功的,它仍然沒有發生。

任何人都可以幫助我找到問題所在?,謝謝。

+1

您需要檢查返回的響應對象。僅僅因爲連接成功並不意味着所請求的操作是成功的。 – Nick 2011-02-24 20:06:48

回答

3

雖然twitter現在只有O-AUTH身份驗證,所以你不能簡單地通過他們的REST服務發佈信息了。

您可能需要重新整合其新的OAUTH服務。

UPDATE:

這裏是鏈接到OAUTH例子: Twitter - OAUTH

,我需要做的令人失望的部分是爲了去通過愚蠢的步驟嘰嘰喳喳現在創建一個Web用戶界面視圖強制執行。在進行身份驗證請求(綁定到在Twitter中創建的應用程序)之後,我的會話被創建並從那裏開始發佈消息。

不像以前的REST服務那麼友好:/

+0

不知道。要搜索一些關於OAUTH認證或實際的Twitter教程的信息。謝謝。 – 2011-02-24 20:07:22

相關問題