2014-02-19 28 views
0

在我的應用程序中,我有一個imageView,我想將圖像發佈到Picasa。
我有一些建議使用GData Framwork。我下載了它從如何在iOS應用中使用GData框架將圖片上傳到Picasa?

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

但是,當我在我的構建階段添加某文件,它顯示紅色。我已經嘗試過所有的方法,以及其他論壇。
是否有任何其他方式將圖片上傳到Picasa。
任何幫助,將不勝感激。

回答

0

我沒有一個應用程序來測試這個,但我已經從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 
    } 

希望這會有所幫助。

+0

笏是驗證碼 – Chandru

+0

雅,謝謝我將chek和讓你知道 – Chandru

+0

urgh ..對不起,這是爲了創建專輯。我編輯了回答 – user1349663

相關問題