我沒有一個應用程序來測試這個,但我已經從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
}
希望這會有所幫助。
笏是驗證碼 – Chandru
雅,謝謝我將chek和讓你知道 – Chandru
urgh ..對不起,這是爲了創建專輯。我編輯了回答 – user1349663