0

In my app, I have an imageView, I want to post the image to Picasa.
I got some suggestion to use GData Framwork. I downloaded it from

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

But, when I add the .a file in my Build phases, it is displayed as red. I have tried all the method in SO, as well as other forums.
Is there any other way to upload image to Picasa.
Any help would be appreciated.

Chandru
  • 247
  • 2
  • 18

1 Answers1

0

I don't have an app to test this with, but I've translated the php-curl solution from this SO question.

    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
    }

Hope this helps.

Community
  • 1
  • 1
user1349663
  • 595
  • 1
  • 7
  • 21
  • urgh.. sorry, that's for creating the album. I've edited the answer – user1349663 Feb 19 '14 at 08:31
  • it enters the if loop, but an image is not uploaded in picasa – Chandru Feb 19 '14 at 08:54
  • data <4d6f6469 66696361 74696f6e 206f6e6c 7920616c 6c6f7765 64207769 74682061 70692061 75746865 6e746963 6174696f 6e2e> Response code 403 – Chandru Feb 19 '14 at 09:30
  • Ah! It needs the authentication header. Try the edits and let me know. (Get the access code: https://developers.google.com/picasa-web/docs/2.0/developers_guide_protocol#Auth) – user1349663 Feb 19 '14 at 09:56
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47832/discussion-between-chandru-and-user1349663) – Chandru Feb 19 '14 at 10:02