我们无法在LinkedIn上找到授权令牌登录iOS sdk
我的iOS应用程序工作正常,但现在我面临的问题是“我们无法找到授权令牌。”这种情况有时会发生(大多数情况下工作正常)。当我试图在桌面上登录我的LinkedIn帐户时,我第一次面临同样的问题。我在许多应用程序中实现了相同的代码,但所有代码都工作正常好,但今天我在我的新应用中遇到了这个问题。我们无法在LinkedIn上找到授权令牌登录iOS sdk
代码段:
请求令牌:
- (void)requestTokenFromProvider
{
LOAMutableURLRequest *request =
[[[LOAMutableURLRequest alloc] initWithURL:requestTokenURL
consumer:self.consumer
token:nil
callback:linkedInCallbackURL
signatureProvider:nil] autorelease];
[request setHTTPMethod:@"POST"];
LOARequestParameter *nameParam = [[LOARequestParameter alloc] initWithName:@"scope" value:@"r_fullprofile+w_messages+r_network+r_emailaddress+rw_nus"];
NSArray *params = [NSArray arrayWithObjects:nameParam, nil];
[request setParameters:params];
LOARequestParameter * scopeParameter=[LOARequestParameter requestParameter:@"scope" value:@"r_fullprofile w_messages r_network r_emailaddress rw_nus"];
[request setParameters:[NSArray arrayWithObject:scopeParameter]];
LOADataFetcher *fetcher = [[[LOADataFetcher alloc] init] autorelease];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(requestTokenResult:didFinish:)
didFailSelector:@selector(requestTokenResult:didFail:)];
}
- (void)requestTokenResult:(LOAServiceTicket *)ticket didFinish:(NSData *)data
{
if (ticket.didSucceed == NO)
return;
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
self.requestToken = [[LOAToken alloc] initWithHTTPResponseBody:responseBody];
[responseBody release];
[self allowUserToLogin];
}
- (void)requestTokenResult:(LOAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
LinkedIn登陆页面和访问令牌:
- (void)allowUserToLogin
{
NSString *userLoginURLWithToken = [NSString stringWithFormat:@"%@?oauth_token=%@",
userLoginURLString, self.requestToken.key];
userLoginURL = [NSURL URLWithString:userLoginURLWithToken];
NSURLRequest *request = [NSMutableURLRequest requestWithURL: userLoginURL];
[webView loadRequest:request];
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
addressBar.text = urlString;
[activityIndicator startAnimating];
BOOL requestForCallbackURL = ([urlString rangeOfString:linkedInCallbackURL].location != NSNotFound);
if (requestForCallbackURL)
{
BOOL userAllowedAccess = ([urlString rangeOfString:@"user_refused"].location == NSNotFound);
if (userAllowedAccess)
{
[self.requestToken setVerifierWithUrl:url];
[self accessTokenFromProvider];
}
else
{
// User refused to allow our app access
// Notify parent and close this view
// [[NSNotificationCenter defaultCenter]
// postNotificationName:@"loginViewDidFinish"
// object:self
// userInfo:nil];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"LinkedInCancelled"];
[[ImpActivityAgent defaultAgent] makeBusy:NO];
[self dismissViewControllerAnimated:NO completion:nil];
}
}
else
{
// Case (a) or (b), so ignore it
}
return YES;
}
- (void)accessTokenFromProvider
{
[[NSUserDefaults standardUserDefaults] setObject:self.consumer forKey:@"LinkedinConsumer"];
LOAMutableURLRequest *request =
[[[LOAMutableURLRequest alloc] initWithURL:accessTokenURL
consumer:self.consumer
token:self.requestToken
callback:nil
signatureProvider:nil] autorelease];
[request setHTTPMethod:@"POST"];
LOADataFetcher *fetcher = [[[LOADataFetcher alloc] init] autorelease];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(accessTokenResult:didFinish:)
didFailSelector:@selector(accessTokenResult:didFail:)];
}
- (void)accessTokenResult:(LOAServiceTicket *)ticket didFinish:(NSData *)data
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
[[NSUserDefaults standardUserDefaults] setObject:responseBody forKey:@"AccessTokenresponseBody"];
BOOL problem = ([responseBody rangeOfString:@"oauth_problem"].location != NSNotFound);
if (problem)
{
NSLog(@"%@",responseBody);
}
else
{
self.accessToken = [[LOAToken alloc] initWithHTTPResponseBody:responseBody];
[[NSUserDefaults standardUserDefaults] setObject:responseBody forKey:@"accessToken"];//save here
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"TokenRefreshDate"];//save here
[[NSUserDefaults standardUserDefaults] synchronize];
}
// Notify parent and close this view
[[NSNotificationCenter defaultCenter]
postNotificationName:@"loginViewDidFinish"
object:self];
[self dismissViewControllerAnimated:NO completion:nil];
[responseBody release];
}
URL请求:
- (void)initLinkedInApi
{
apikey = @"vwu3pmtjaxyz";
secretkey = @"XkPxP1DNANMg0Dzq";
self.consumer = [[LOAConsumer alloc] initWithKey:apikey
secret:secretkey
realm:@"http://api.linkedin.com/"];
requestTokenURLString = @"https://api.linkedin.com/uas/oauth/requestToken";
accessTokenURLString = @"https://api.linkedin.com/uas/oauth/accessToken";
userLoginURLString = @"https://www.linkedin.com/uas/oauth/authorize";
linkedInCallbackURL = @"hdlinked://linkedin/oauth";
requestTokenURL = [[NSURL URLWithString:requestTokenURLString] retain];
accessTokenURL = [[NSURL URLWithString:accessTokenURLString] retain];
userLoginURL = [[NSURL URLWithString:userLoginURLString] retain];
}
请问有人可以告诉我背后有什么理由吗?
我已将此问题发布到LinkedIn论坛,因为其他开发人员也向他们报告了这个问题。
As per Kamyar Mohager LinkedIn Employee
是当你授权一个新用户或者是你试图与现有的访问令牌的调用会这样呢?根据该错误消息,我的假设是,您通过身份验证流程访问用户,并在重定向到LinkedIn.com时看到错误消息。请确认。我们正在研究这个问题,因为其他开发者已经报道过这个问题
然后只有下面的评论他已经确定问题已经解决。
他说:
我们的团队已经解决了“我们无法找到授权令牌”,通过身份验证流程,将用户重定向时的问题。请让我知道你们中的任何人是否继续遇到这个问题。
感谢您使用此最新信息更新您的信息。我重新测试过,但无法重现错误。看起来他们确实在他们身上修理了一些东西。 – mainframe
我也面临同样的问题。 –