1

我已经向服务器发送了一个请求,以使用 OAuth 获取 atom 提要,但不幸的是http 401 Error,每次请求后我都获得了 Authentication Failed。请找到以下代码以供参考:

-(void)loadOAuthRequest:(NSString*)authToken
{
    NSString *accessToken=[NSString stringWithFormat:@"Bearer=%@",authToken];
    NSString *gmailAPI = @"https://mail.google.com/mail/feed/atom/";
    NSLog(@"%@",gmailAPI);
    NSURL *url = [NSURL URLWithString:gmailAPI];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"GET"];    
    NSLog(@"Access token : %@",accessToken);
    [request setValue:accessToken forHTTPHeaderField:@"Authorization"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request   delegate:self];
    [connection start];
}

这是我使用的,但出现以下错误,如下所示:

<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>

谁能告诉我如何使用 OAuth 访问令牌向服务器发送请求以获取 gmail 内容。

4

0 回答 0