I am trying to get Google OAuth working on iOS so I can make requests to the Google Calendar API. I am currently using this code to load a Google login sheet into a UIWebView
and try to get an access token back..
[AISWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/calendar&redirect_uri=%@&response_type=code&client_id=%@",kSharedURI,kClientId]]]];
I am managing to get what I think is the access token from a text field that appears here, by parsing the HTML again and again using NSString
. But when I attempt to use what I think is the access token to make this calendar request using NSMutableURLRequest
, I get a response from Google saying
error = {
code = 401;
errors = (
{
domain = global;
location = Authorization;
locationType = header;
message = "Login Required";
reason = required;
}
);
message = "Login Required";
};
If anyone has any ideas they would be absolutely appreciated.
First of all please note that I'm not familiar with Google's API.
I think you're sending the OAuth data as parameters in the request. But they request them as an Authentication Header. You should use a framework like NSURLConnection (or 3rd party frameworks) to add those headers.
Refer to this: NSURLConnection and Basic HTTP Authentication in iOS for an example
Good luck