2011-01-15 8 views
1

Ich versuche, den Token von Google Reader für mein iPhone-Projekt zu bekommen. Ich bin in der Lage, die Autorisierung zu bekommen, aber wenn ich um das Token ersuche, bekomme ich eine 403 verbotenGoogle Reader Token Anfrage geben 403 Fehler

Unten ist meine Code-Implementierung. Jede Hilfe wäre willkommen.

//The tokenStorer contains the Authorization key 
NSString *tokenStorer = [[NSUserDefaults standardUserDefaults]valueForKey:@"authKey"]; 
    NSLog(@"%@", tokenStorer); 
    NSDictionary *cookieDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"www.google.com", @"Host", 
             @"iReader", @"User-Agent", 
             @"gzip, deflate", @"Accept-Encoding", 
             tokenStorer, @"Authorization", 
             nil 
             ]; 

    //@"Auth", NSHTTPCookieName, tokenStorer, NSHTTPCookieValue, @"./google.com", NSHTTPCookieDomain, @"/", NSHTTPCookiePath, nil]; 
    //NSHTTPCookie *authCookie = [NSHTTPCookie cookieWithProperties:cookieDictionary]; 

//Google token url "http://www.google.com/reader/api/0/token?client=clientName" 
    NSURL *url=[[NSURL alloc] initWithString:GOOGLE_READER_TOKEN_URL]; 
    NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]initWithURL:url]; 
    [urlRequest setHTTPMethod:@"GET"]; 
    [urlRequest setAllHTTPHeaderFields:cookieDictionary]; 
    NSData *reciveData; 
    NSURLResponse *response; 
    NSError *error; 
    reciveData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; 
    NSMutableURLRequest *tokenRequest= [[NSMutableURLRequest alloc] initWithURL:url]; 
    NSString *trial = [[NSString alloc]initWithData:reciveData encoding:NSASCIIStringEncoding]; 
    NSLog(@"%@ %d",trial, response); 
    [url release]; 

Antwort

1

Der Code unten mein Problem gelöst:

-(id)queryLoginDetails { 
     //authKey returns the authorization key 
    NSString *tokenStorer = [[NSUserDefaults standardUserDefaults]valueForKey:@"authKey"]; 
     NSLog(@"%@", tokenStorer); 
    NSString *auth = [[NSString alloc] initWithString: 
      [NSString stringWithFormat:@"GoogleLogin auth=%@", [tokenStorer substringToIndex:[tokenStorer length]-1]]]; 
    NSDictionary *createHeader = [[NSDictionary dictionaryWithObjectsAndKeys:@"www.google.com", @"Host", @"iReader", @"User-Agent", @"gzip, deflate", @"Accept-Encoding", auth, @"Authorization", nil]retain]; 
    NSURL *url =[NSURL URLWithString:GOOGLE_READER_TOKEN_URL]; 
    NSData *recieveData; 
    NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]initWithURL:url]; 
    [urlRequest setHTTPMethod:@"GET"]; 
    [urlRequest setAllHTTPHeaderFields:createHeader]; 
    NSURLResponse *response; 
    NSError *error; 
    recieveData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; 
    NSString *myString = [[NSString alloc]initWithData:recieveData encoding:NSASCIIStringEncoding]; 
    return myString; 
} 
Verwandte Themen