通过GTMOAuth使用RESTapi使委托在成功登录dropbox时回调



我已经使用GTMOAuth成功登录到dropbox,但在返回响应后,我似乎无法让委托回调我有这个代码可以登录。。

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,这对我来说已经足够了

最新更新