【问题标题】:How to twit a picture with some text in iPhone如何在 iPhone 中发布带有一些文字的图片
【发布时间】:2011-02-28 08:33:01
【问题描述】:

我想知道有什么方法可以在推特上发布带有一些文字的图片,有人建议使用“http://tinyurl.com/”。我不知道从哪里开始,在我的以前的应用程序我成功地推特,但只包含文本。 正确的前进方向会很有帮助。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    有几种方法。我建议你使用ShareKit。它会为您完成大部分工作。

    【讨论】:

    • 实际上我找到了我想要的解决方案无法实现,twitter 不会在任何 twit 中显示图像,而是通过单击图像链接在不同的窗口中显示图像...... . 我们使用 tinyurl,因为 url 实际上可能非常长,而 twitter 仅支持 140 个字符。虽然您的链接为我提供了一个很好的 api 供进一步使用......谢谢你:)
    【解决方案2】:

    要将图像发布到推特,我们必须首先将图像发布到推特选择,然后我们必须将该 URL 发送到推特,这是将图像发送到推特的过程这是将图像发送到推特的示例代码...... .......

    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];  
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 2014-04-19
      相关资源
      最近更新 更多