Auth not working for me in objective c

6 views
Skip to first unread message

itgiawa

unread,
Aug 29, 2010, 2:19:32 PM8/29/10
to Friends of the Unofficial Google Reader API
My app used to work with SID. Now trying to use the Auth header I keep
getting 401 errors.

NSString* url = @"http://www.google.com/reader/atom/user/-/pref/
com.google/subscriptions";
NSMutableURLRequest *subscriptionRequest = [[[NSMutableURLRequest
alloc] init] autorelease];
[subscriptionRequest setURL:[NSURL URLWithString:url]];
[subscriptionRequest setHTTPMethod:@"GET"];
[subscriptionRequest setValue:[NSString
stringWithFormat:@"GoogleLogin auth=%@", AUTH]
forHTTPHeaderField:@"Authorization"];
[subscriptionRequest setValue:@"application/x-www-form-urlencoded"
forHTTPHeaderField:@"Content-Type"];
[subscriptionRequest setTimeoutInterval:30.0];

Can anyone give me any hints? I'm pretty sure I'm parsing my auth
string correctly...

Robert Seifert

unread,
Aug 29, 2010, 9:33:59 PM8/29/10
to Friends of the Unofficial Google Reader API
That looks correct to me. For what it's worth, here is the code that I
am using:

NSURL *url = [[NSURL alloc] initWithString: targetUrl];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL: url];
NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setValue: @"application/x-www-form-urlencoded" forKey:
@"Content-Type"];
[headers setValue: [NSString stringWithFormat: @"GoogleLogin auth=%@",
auth] forKey: @"Authorization"];
[request setAllHTTPHeaderFields: headers];

The above code connects for me without any problem.

Robert

itgiawa

unread,
Aug 31, 2010, 12:14:30 PM8/31/10
to Friends of the Unofficial Google Reader API
Hmm using your code I keep getting 401 "client error"s and a response
statusCode of 0.

This means my problem is either with the url:
http://www.google.com/reader/atom/user/-/pref/com.google/subscriptions
or my auth token, which I'm parsing like this: AUTH = [responseStr
stringBetween:@"AUTH=" and:@"\n"];
and tends to be either 203 or 224 characters in length.

Does this seem right to you?
Can you think of any other mistake I could be overlooking?

Thanks!

Robert Seifert

unread,
Sep 1, 2010, 4:28:56 PM9/1/10
to Friends of the Unofficial Google Reader API
I'm not familiar with the stringBetween method, but could the problem
be with @"AUTH="? When I get the string back from Google the string
is "Auth=", so unless the stringBetween method is ignoring case, that
may be causing a problem. I use the following code to parse out the
auth:

NSRange range = [responseStr rangeOfString: @"Auth="];
int beginAuth = range.location + 5;
int length = [responseStr length] - beginAuth - 1;
NSString auth = [[NSString alloc] initWithString:
[responseStr substringWithRange: NSMakeRange(beginAuth,
length)]];

Hope that helps.

Robert
Reply all
Reply to author
Forward
0 new messages