Как получить изображения из Instagram со специальным хэштегом?

Мой клиент хочет поделиться изображением в Instagram. Я реализовал обмен изображением в instagram. Но я не мог поделиться им со специальным хэштегом. Вот мой код до сих пор.

- (IBAction)sharePhotoOnInstagram:(id)sender {

    UIImagePickerController *imgpicker=[[UIImagePickerController alloc] init];
    imgpicker.delegate=self;
    [self storeimage];
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
    {

        CGRect rect = CGRectMake(0 ,0 , 612, 612);
        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/15717.ig"];

        NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
        dic.UTI = @"com.instagram.photo";
        dic.delegate = self;
        dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
        dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
        dic.delegate = self;
        [dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
        //  [[UIApplication sharedApplication] openURL:instagramURL];
    }
    else
    {
        //   NSLog(@"instagramImageShare");
        UIAlertView *errorToShare = [[UIAlertView alloc] initWithTitle:@"Instagram unavailable " message:@"You need to install Instagram in your device in order to share this image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        errorToShare.tag=3010;
        [errorToShare show];
    }
}


- (void) storeimage
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"15717.ig"];
    UIImage *NewImg = [self resizedImage:picTaken :CGRectMake(0, 0, 612, 612) ];
    NSData *imageData = UIImagePNGRepresentation(NewImg);
    [imageData writeToFile:savedImagePath atomically:NO];
}

-(UIImage*) resizedImage:(UIImage *)inImage: (CGRect) thumbRect
{
    CGImageRef imageRef = [inImage CGImage];
    CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);

    // There's a wierdness with kCGImageAlphaNone and CGBitmapContextCreate
    // see Supported Pixel Formats in the Quartz 2D Programming Guide
    // Creating a Bitmap Graphics Context section
    // only RGB 8 bit images with alpha of kCGImageAlphaNoneSkipFirst, kCGImageAlphaNoneSkipLast, kCGImageAlphaPremultipliedFirst,
    // and kCGImageAlphaPremultipliedLast, with a few other oddball image kinds are supported
    // The images on input here are likely to be png or jpeg files
    if (alphaInfo == kCGImageAlphaNone)
        alphaInfo = kCGImageAlphaNoneSkipLast;

    // Build a bitmap context that's the size of the thumbRect
    CGContextRef bitmap = CGBitmapContextCreate(
                                                NULL,
                                                thumbRect.size.width,       // width
                                                thumbRect.size.height,      // height
                                                CGImageGetBitsPerComponent(imageRef),   // really needs to always be 8
                                                4 * thumbRect.size.width,   // rowbytes
                                                CGImageGetColorSpace(imageRef),
                                                alphaInfo
                                                );

    // Draw into the context, this scales the image
    CGContextDrawImage(bitmap, thumbRect, imageRef);

    // Get an image from the context and a UIImage
    CGImageRef  ref = CGBitmapContextCreateImage(bitmap);
    UIImage*    result = [UIImage imageWithCGImage:ref];

    CGContextRelease(bitmap);   // ok if NULL
    CGImageRelease(ref);

    return result;
}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate
{  
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    interactionController.delegate = self;

    return interactionController;
}

- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller
{

}

- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller canPerformAction:(SEL)action
{
    //    NSLog(@"5dsklfjkljas");
    return YES;
}

- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller performAction:(SEL)action
{ 
    //    NSLog(@"dsfa");
    return YES;
}

- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application
{
    //    NSLog(@"fsafasd;");
}

Примечание. Это работает нормально.

Я следил за их документацией на http://instagram.com/developer/iphone-hooks/ но лучше не придумаешь!. Теперь не знаю, что делать дальше, чтобы поделиться изображением с хэштегом и другой информацией.

Во-вторых, я хочу загрузить в приложение все изображения, которыми поделились с определенным хэштегом.

Пожалуйста, направьте меня! Заранее спасибо!


person happycoder    schedule 03.04.2013    source источник


Ответы (1)


Во-первых, из перехватчиков iPhone в разделе "Взаимодействие с документом":

Чтобы включить предварительно заполненную подпись к вашей фотографии, вы можете установить свойство аннотации в запросе взаимодействия с документом на NSDictionary, содержащее NSString под ключом «InstagramCaption». Примечание: эта функция будет доступна в Instagram 2.1 и более поздних версиях.

Вам нужно будет добавить что-то вроде:

dic.annotation = [NSDictionary dictionaryWithObject:@"#yourTagHere" forKey:@"InstagramCaption"];

Во-вторых, вам нужно взглянуть на Конечные точки тегов, если вы хотите вытащить изображения. с определенным тегом.

person kyleobrien    schedule 04.04.2013
comment
Спасибо, Кайл! Большое спасибо. Можем ли мы получить несколько изображений, которыми поделились с одним и тем же тегом разные пользователи? - person happycoder; 05.04.2013