从响应string中提取令牌
如何从响应string中提取令牌? (我不知道令牌的长度,所以我不能在这里使用NSRange)
oauth_callback_confirmed=true&oauth_token=72157632316931441 -fadcd6ef70cbd06c&oauth_token_secret=a7e7b046a8960559
当前的代码是(它给出令牌和string的其余部分):
NSRange access_token_range = [operation.responseString rangeOfString:@"oauth_token="]; if (access_token_range.length > 0) { int from_index = access_token_range.location + access_token_range.length; NSString *access_token = [operation.responseString substringFromIndex:from_index]; NSLog(@"access_token: %@", access_token); }
将响应string分隔到键值对然后分别处理它们会更好(更优雅):
NSString *token = nil; NSArray *kvpairs = [operation.responseString componentsSeparatedByString:@"&"]; for (NSString *kvpair in kvpairs) { NSArray *keyAndValue = [kvpair componentsSeparatedByString:@"="]; NSString *key = [keyAndValue objectAtIndex:0]; if ([key isEqualToString:@"oauth_token"]) { token = [keyAndValue objectAtIndex:1]; break; } }
现在token
将包含令牌或nil
如果无法find。
- 将UIGestureRecognizer添加到UILabel的单个字母
- stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)在Swift中返回Optional
- 如何在Visual Studio 2015中设置OAuth以使用Google身份验证
- 将现有OAuth凭据迁移到ACAccountStore时出错
- Google OAuth不再支持渐进式应用程序?
- iOS Google Drive SDK使用关键“webContentLink”将文件加载到UIWebView中
- 优步无效的OAuth 2.0凭据提供Uber身份validation在iOS Swift中
- 与parse-server和auth0的定制authentication集成
- 无法从iOS OAuth1.0,OAC消费者客户端的tumblr上发布
- 如何在使用Facebook iPhone SDK时刷新oauth标记
- 从LinkedIn API获取电子邮件地址