Google Reader Token 请求出现 403 错误

发布于 2024-10-12 00:44:28 字数 1688 浏览 5 评论 0原文

我正在尝试从 google reader 获取我的 iPhone 项目的令牌。我能够获得授权,但是当我请求令牌时,我收到 403 Forbidden

下面是我的代码实现。任何帮助将不胜感激。

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

I am trying to get the token from google reader for my iPhone project. I am able to get the Authorization but when I request for the token, I get a 403 Forbidden

Below is my code implementation. Any help would be appreciated.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情独悲 2024-10-19 00:44:28

下面的代码解决了我的问题:

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

The below code solved my problem:

-(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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文