我已使用 GTMOAuth 成功登录到保管箱,但一旦返回响应,我似乎无法让委托(delegate)回调 我有这个代码可以登录..
NSURL *requestURL = [NSURL URLWithString:@"https://api.dropbox.com/1/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:@"https://api.dropbox.com/1/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:@"https://www.dropbox.com/1/oauth/authorize"];
NSString *scope = nil;
GTMOAuthAuthentication *auth = [self authForTwitter];
if (auth == nil) {
// perhaps display something friendlier in the UI?
NSAssert(NO, @"A valid consumer key and consumer secret are required for signing in to Twitter");
}
// set the callback URL to which the site should redirect, and for which
// the OAuth controller should look to determine when sign-in has
// finished or been canceled
//
// This URL does not need to be for an actual web page; it will not be
// loaded
[auth setCallback:@"https://www.dropbox.com"];
NSString *keychainItemName = nil;
if ([self shouldSaveInKeychain]) {
keychainItemName = kTwitterKeychainItemName;
}
// Display the autentication view.
GTMOAuthViewControllerTouch *viewController;
viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
requestTokenURL:requestURL
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:keychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];
// We can set a URL for deleting the cookies after sign-in so the next time
// the user signs in, the browser does not assume the user is already signed
// in
[viewController setBrowserCookiesURL:[NSURL URLWithString:@"http://api.dropbox.com/"]];
// You can set the title of the navigationItem of the controller here, if you want.
[[self navigationController] pushViewController:viewController animated:YES];
我尝试过编辑库的内容,但没有成功。
最佳答案
遇到同样的问题。经过一些调试后,问题似乎是回调 URL 未包含在“6.2.1. 消费者将用户引导至服务提供商”步骤 ( http://oauth.net/core/1.0a/#auth_step2 ) 中。根据 OAuth 规范,它不应该,但 Dropbox 要求它执行重定向。
为了测试,我像这样更改了 GTMOAuthAuthentication.m:
+ (NSArray *)tokenAuthorizeKeys {
// keys for opening the authorize page, http://oauth.net/core/1.0a/#auth_step2
NSArray *keys = [NSArray arrayWithObjects:
kOAuthTokenKey,
// extensions
kOAuthDomainKey,
kOAuthHostedDomainKey,
kOAuthLanguageKey,
kOAuthMobileKey,
kOAuthScopeKey,
kOAuthCallbackKey, // !pi! 20120313 dropbox testing
nil];
return keys;
}
即还将回调 URL 添加到此步骤。现在 GTMOAuth 可以与 Dropbox 配合使用。
应该有更好的解决方案来做到这一点,但我只是测试 GTMOAuth/RESTKit,这对我来说已经足够了。
关于ios - 通过 GTMOAuth 使用 REST api 让代理在成功登录保管箱时进行回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9411695/