2012-02-04 64 views
0

我試圖連接到谷歌的RESTful API的但我得到就去這麼做是一個登錄界面。iOS和谷歌的API REST

我的目標是能夠創建使用REST風格的谷歌日曆日曆。

我已經創建了谷歌API控制檯我的API密鑰。

我這樣做:

NSString* baseURL = @"https://accounts.google.com/o/oauth2/auth?"; 
NSString* url = [NSString stringWithFormat:@"%@%@",baseURL,[self dictionaryToURLStringVariables:[self authParameters]]]; 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; 
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

驗證參數

-(NSDictionary*)authParameters 
{ 
    NSDictionary* dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"code",@"response_type", redirectURI,@"redirect_uri", API_ID,@"client_id", @"https://www.googleapis.com/auth/calendar",@"scope", nil]; 
    return dictionary; 
} 

的響應,工作正常,但我得到的是谷歌的HTML登錄。

我檢查了與谷歌有它自己的Objective-C庫是從我的角度來看過於複雜,不是基於的iDevices但桌面。

我第一個問題是:

有沒有一種簡單的方法通過REST做這一切(登錄,令牌,CRUD ...)只發送和張貼請求?

e.g:http://www.googleapis.com/login?user=MY_EMAIL&password=MY_PASSWORD(< - 當然不是不是簡單/不安全,但你的想法...)

+0

請限制每個崗位一個問題。 – Rayfleck 2012-02-04 16:35:49

+0

我刪除了第二個。謝謝 – 2012-02-04 16:38:17

+0

好的,我刪除了第二個答案:-) – Rayfleck 2012-02-04 16:41:26

回答

0

對於問題1,儘量實現此NSURLConnection的委託方法。它允許您在服務要求時提供憑證。

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge