我正在构建一个 iOS 应用程序,客户可以在其中登录(使用相同的网站用户名和密码)到该应用程序并从该应用程序购买商品。woo commerce 的其余 api 表示通过提供 API Consumer Key 作为用户名和 API Consumer Secret 作为密码来使用 HTTP Basic Auth。我一直在研究很多,但我真的无处可去。现在我正在尝试 AFOAuth2manager,这是我的代码,我到目前为止没有工作
NSURL *baseURL = [NSURL URLWithString:urlString];
AFOAuth2Manager *oAuthManager = [[AFOAuth2Manager alloc] initWithBaseURL:baseURL
clientID: keyClientID
secret:keyClientSecret];
[oAuthManager authenticateUsingOAuthWithURLString:@"/oauth/token"
username:myUserName
password:myPassword
scope:@"email"
success:^(AFOAuthCredential *credential) {
NSLog(@"Token: %@",credential.accessToken);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
//Authorizing requests
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:keyClientID password:keyClientSecret];
[manager GET:@"/path/to/protected/resource"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Succes: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
}];
//storing credentials
AFOAuthCredential *credential = [[AFOAuthCredential alloc] init];
[AFOAuthCredential storeCredential: credential withIdentifier:serviceProviderIdentifier];
//retrieving credentials
AFOAuthCredential *storedCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:serviceProviderIdentifier];
NSLog(@"%@", storedCredential);
我收到此错误:NSLocalizedDescription=Request failed: not found (404),以及一长串数字。无论如何,我正在寻找有关该过程的一些指南,我需要让用户登录我的应用程序,我的应用程序确认用户在网站上有一个帐户,用户可以在我的应用程序上购买商品,然后我将订单发布到网站进行处理。任何帮助是极大的赞赏