简体   繁体   中英

Upload Multiple Photos to Twitter Using STTwitter

I know that you can put up to four images in a tweet, so I was wondering if that was possible, possibly using STTwitter I know that you can upload one image using this method in STTwitter, but as far as I know this method doesn't support multiple images:

- (NSObject<STTwitterRequestProtocol> *)postMediaUpload:(NSURL *)mediaURL
                                    uploadProgressBlock:(void(^)(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite))uploadProgressBlock
                                           successBlock:(void(^)(NSDictionary *imageDictionary, NSString *mediaID, NSString *size))successBlock
                                             errorBlock:(void(^)(NSError *error))errorBlock

Worth mentioning I'm building this into an iOS app using Objective-C

1) post medias and store their IDs, as documented in POST media/upload

for(NSString *filename in @[@"1.png", @"2.png", @"3.png", @"4.png"]) {
    NSString *filePath = [[@"~/Desktop/" stringByExpandingTildeInPath] stringByAppendingPathComponent:filename];
    NSURL *fileURL = [NSURL fileURLWithPath:filePath];

    [_twitter postMediaUpload:fileURL
          uploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
              NSLog(@"..");
          } successBlock:^(NSDictionary *imageDictionary, NSString *mediaID, NSString *size) {
              NSLog(@"-- %@", mediaID);
          } errorBlock:^(NSError *error) {
              NSLog(@"-- %@", [error localizedDescription]);
          }];
}

2) post status and fill mediaIDs, as documented in POST statuses/update

[_twitter postStatusUpdate:@"hello"
         inReplyToStatusID:nil
                  mediaIDs:@[@"620502730948218882", @"620502730948239360", @"620502731610984448", @"620502731623534592"]
                  latitude:nil
                 longitude:nil
                   placeID:nil
        displayCoordinates:nil
                  trimUser:nil
              successBlock:^(NSDictionary *status) {
                  NSLog(@"-- %@", status);
              } errorBlock:^(NSError *error) {
                  NSLog(@"-- %@", [error localizedDescription]);
              }];

3) there's no step three :-)

https://twitter.com/nst022/status/620503183564107776

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM