Mc-
Mc-

Reputation: 4056

iOS and Google APIs REST

I'm trying to connect to Google RESTful API's but all I get went doing so is a login screen.

My goal is to be able to create a Calendar in Google Calendars using RESTful.

I already created my API keys on Google APIs Console.

I did this:

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];

Auth parameters

-(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;
}

The response is working fine but all I get is a Google HTML login.

I checked out and google has it's own Objective-C library which is far too complicated from my point of view and is not based on iDevices but Desktop.

My first question is:

Is there a SIMPLE way to do it all via REST ( login, token, CRUD... ) just sending and posting requests?

e.g: http://www.googleapis.com/login?user=MY_EMAIL&password=MY_PASSWORD (<- of course not than simple / insecure but you get the idea...)

Upvotes: 0

Views: 504

Answers (1)

Rayfleck
Rayfleck

Reputation: 12106

For question 1, try implementing this NSURLConnection delegate method. It allows you to supply credentials when the service asks for them.

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

Upvotes: 0

Related Questions