2011-02-28 45 views
0

我想知道,有什麼方法可以在twitter中用一些文字發佈圖片,有人建議使用「http://tinyurl.com/」。我不知道從哪裏開始,在我的以前的應用程序中,我成功地抽動了,但只包含文本。 正確的方向繼續將是一個很大的幫助。如何用iPhone中的某些文字抽出圖片

回答

1

有幾種方法。我建議你使用ShareKit。它爲你做了大部分工作。

+0

其實我發現,我想要的是無法實現的,微博,不以任何TWIT顯示圖像,而它通過點擊顯示在不同的窗口中的圖像解決方案鏈接的圖像....我們使用tinyurl,因爲url的長度實際上可以非常大,twitter只支持140個字符。雖然你的鏈接爲我提供了一個很好的API用於進一步使用...感謝那:) – 2011-02-28 09:52:38

0

要將圖像發佈到Twitter,我們必須先將圖像發佈到twit中,然後我們必須將該網址發送到twitter,這是將圖像發送到twitter的過程,這是將圖像發送到twitter的示例代碼。 ........

NSString *postUrl = @"https://api.twitter.com/1/statuses/update.json"; 

ASIFormDataRequest *request = [[ASIFormDataRequest alloc] 
           initWithURL:[NSURL URLWithString:postUrl]]; 

NSMutableDictionary *postInfo = [NSMutableDictionary 
           dictionaryWithObject:statusText.text 
           forKey:@"status"]; 

NSLog(@"%@",postInfo); 
NSString *str1= statusText.text; 

NSLog(@"Status posted. HTTP result code: %d", request.responseStatusCode); 



[request release]; 

[statusText resignFirstResponder]; 

ASIFormDataRequest *req = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitpic.com/2/upload.json"]]; 


[req addRequestHeader:@"X-Auth-Service-Provider" value:@"https://api.twitter.com/1/account/verify_credentials.json"]; 
[req addRequestHeader:@"X-Verify-Credentials-Authorization" 
       value:[oAuth oAuthHeaderForMethod:@"GET" 
              andUrl:@"https://api.twitter.com/1/account/verify_credentials.json" 
             andParams:nil]];  
[req setData:UIImageJPEGRepresentation(imageView.image, 0.8) forKey:@"media"]; 

// Define this somewhere or replace with your own key inline right here. 

[req setPostValue:@"74734e805f2ad85afae441ca12c16087" forKey:@"key"]; 
[req startSynchronous]; 

NSLog(@"Got HTTP status code from TwitPic: %d", [req responseStatusCode]); 

NSLog(@"Response string: %@", [req responseString]); 


NSDictionary *twitpicResponse = [[req responseString] JSONValue]; 
NSLog(@"%@",[[req responseString] JSONValue]); 
textView.text = [NSString stringWithFormat:@"Posted image URL: %@", [twitpicResponse valueForKey:@"url"]]; 
NSString *str=[NSString stringWithFormat:@" %@",[twitpicResponse valueForKey:@"url"]]; 
NSLog(@"%@",str); 
if([str isEqualToString:@" (null)"]) 
{ 
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Could not authenticate you(header rejected by twitter)" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
    [alertView show]; 
} 
else 
{ 

    NSString *postUrl = @"https://api.twitter.com/1/statuses/update.json"; 

    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] 
            initWithURL:[NSURL URLWithString:postUrl]]; 
    NSString *txtmessage=[str1 stringByAppendingString:str]; 

    /*NSMutableDictionary *postInfo = [NSMutableDictionary 
            dictionaryWithObject:[twitpicResponse valueForKey:@"url"] 
            forKey:@"status"];*/ 
    NSMutableDictionary *postInfo = [NSMutableDictionary 
            dictionaryWithObject:txtmessage 
            forKey:@"status"]; 
    for (NSString *key in [postInfo allKeys]) { 
     [request setPostValue:[postInfo objectForKey:key] forKey:key]; 
    } 

    [request addRequestHeader:@"Authorization" 
         value:[oAuth oAuthHeaderForMethod:@"POST" 
                andUrl:postUrl 
               andParams:postInfo]]; 

    [request startSynchronous]; 

    if(request.responseStatusCode!=200) 
    { 
     UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Already posted" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alertView show]; 
    } 
    else { 
     UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"sucess" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alertView show]; 
    } 


    NSLog(@"Status posted. HTTP result code: %d", request.responseStatusCode); 

    statusText.text = @""; 

    [request release]; 

    [statusText resignFirstResponder]; 
} 
相關問題