【问题标题】:Using Twitter API's upload_with_media with iOS SDK?将 Twitter API 的 upload_with_media 与 iOS SDK 一起使用?
【发布时间】:2013-09-27 14:44:07
【问题描述】:

我一直在寻找 this PHP code sample 的 Objective-C 版本,了解如何将 Twitter 的 upload_with_media 用于 iPhone 应用程序。

我已经找到了。你能给我举个例子或者解释一下我如何把这段代码翻译成Objective-C吗?

谢谢

【问题讨论】:

标签: iphone ios twitter


【解决方案1】:

你可以对upload_with_media这样做,

TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];

            UIImage * image = [UIImage imageNamed:@"myImage.png"];

            //add text
            [postRequest addMultiPartData:[@"I just found the secret level!" dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"];
            //add image
            [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/form-data"];

            // Set the account used to post the tweet.
            [postRequest setAccount:twitterAccount];

            // Perform the request created above and create a handler block to handle the response.
            [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
            }];

【讨论】:

    猜你喜欢
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2017-04-05
    • 2013-04-14
    • 2013-06-23
    • 1970-01-01
    相关资源
    最近更新 更多