OAUth 1 で Web サービスに接続するアプリを作ろうとしていますが、うまくいきません。これが私のgetリクエストでの私の方法です:
- (void)loadUserProfile
{
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[baseUrl]];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:[NSString stringWithFormat:@"/1/user/%@/profile.json", [SSKeychain passwordForService:@"[service]" account:@"encoded_user_id"]]
parameters:nil];
NSString *postString = [NSString stringWithFormat:@"oauth_consumer_key=%@&oauth_token=%@&oauth_nonce=%@&oauth_signature_method=%@&oauth_timestamp=%@&oauth_version=%@", self.auth.consumerKey, [SSKeychain passwordForService:@"[service]" account:@"oauth_token"], self.auth.nonce, self.auth.signatureMethod, self.auth.timestamp, self.auth.version];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
}
このメソッドを呼び出すと、次のエラーが発生します。
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x8efa7f0 {NSErrorFailingURLStringKey=https://api.fitbit.com/1/user/[id]/profile.json, NSErrorFailingURLKey=https://api.fitbit.com/1/user/[id]/profile.json, NSLocalizedDescription=The network connection was lost., NSUnderlyingError=0x8bdb2c0 "The network connection was lost."}
私が取得しようとしているリソースは、https ://wiki.fitbit.com/display/API/OAuth+Authentication+in+the+Fitbit+API#OAuthAuthenticationintheFitbitAPI-tokenCredentials に記載されています。
以前に使用OAuth 1
したことがなく、このエラーを見たことがないため、解決方法がわかりません。何か案は?