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 に答える