0

我已经使用 GTMOAuth 成功登录到保管箱,但是一旦返回响应,我似乎无法让委托回调我有这个代码可以登录..

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];

我曾尝试编辑图书馆但没有成功。

4

1 回答 1

1

碰到同样的问题。经过一些调试后,问题似乎是回调 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,这对我来说已经足够了。

于 2012-03-13T12:17:02.717 回答