【问题标题】:How to use GData framework in iOS app to upload images to Picasa?如何在 iOS 应用程序中使用 GData 框架将图像上传到 Picasa?
【发布时间】:2014-02-19 17:55:14
【问题描述】:

在我的应用中,我有一个 imageView,我想将图片发布到 Picasa。
我得到了一些使用 GData 框架的建议。我从

下载的

code.google.com/p/gdata-objectivec-client/downloads/list

但是,当我在构建阶段添加 .a 文件时,它显示为红色。我已经尝试过 SO 中的所有方法,以及其他论坛。
有没有其他方法可以将图片上传到 Picasa。
任何帮助将不胜感激。

【问题讨论】:

    标签: ios gdata picasa


    【解决方案1】:

    我没有应用程序来测试这个,但我已经从this SO question 翻译了 php-curl 解决方案。

        NSString *authCode = [NSString stringWithFormat:@"GoogleLogin auth=",@"ACCESS CODE FROM OAUTH2"];
        NSString *userId = @"USER ID GOES HERE";
        NSString *albumId = @"ALBUM ID GOES HERE";
        NSString *albumUrl = [NSString stringWithFormat:@"https://picasaweb.google.com/data/feed/api/user/%@/albumid/%@",userId, albumId];
    
    
        // To get the data from a PNG file
        NSData *postData = UIImagePNGRepresentation([UIImage imageNamed:@"YOUR IMAGE"]);
    
        // To get the data from a JPEG file
        //NSData *postData = UIImageJPEGRepresentation([UIImage imageNamed:@"YOUR IMAGE"], 0.9f);
    
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
        // Init and set fields of the URLRequest
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setHTTPMethod:@"POST"];
        [request setURL:[NSURL URLWithString:[NSString stringWithString:albumUrl]]];
        [request setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"2" forHTTPHeaderField:@"GData-Version"];
        [request setValue:authCode forHTTPHeaderField:@"Authorization"];
        [request setHTTPBody:postData];
    
        NSURLResponse* rep = nil;
        NSError *err = nil;
        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&rep error:&err];
    
        if (data && !err) {
            //Do something with the response
        }
    

    希望这会有所帮助。

    【讨论】:

    猜你喜欢
    • 2012-04-03
    • 2012-07-28
    • 1970-01-01
    • 2016-04-14
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    相关资源
    最近更新 更多