我正在尝试从盒子用户帐户中获取数据。现在我已经生成了令牌,但我无法获取根文件夹内容(例如)。
要获得令牌,我会通过以下请求获得票证:
https://www.box.com/api/1.0/rest?action=get_ticket&api_key=BoxApiKey
之后,我在我的应用程序中调用 webView 来加载此页面:
https://m.box.com/api/1.0/auth/ticket
用户登录成功后,我解析网页并提取令牌。
现在出现问题,我无法获取根文件夹内容。这就是我尝试使用 AFNetworking 的方法:
我在 AFHTTPClient 类中添加了这个方法(如她所建议的那样)
-(void)setAuthorizationHeaderWithTokenBearer:(NSString *)token { [self setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Bearer %@", token]]; }
我的电话:
NSURL *url = [NSURL URLWithString:@"https://www.box.com/api/2.0/folders/0"]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; [httpClient setAuthorizationHeaderWithTokenBearer:token]; [httpClient postPath:@"" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"Request Successful, response '%@'", responseStr); } failure:^(AFHTTPRequestOperation *operation, NSError *e) { NSLog(@"[HTTPClient Error]: %@", e.localizedDescription); }];
但我有这个本地化描述:
[HTTPClient Error]: Expected status code in (200-299), got 401
你能帮我解决这个问题吗?谢谢你。