【问题标题】:finishedWithAuth method not gets called after authentication completion身份验证完成后不会调用finishedWithAuth 方法
【发布时间】:2013-05-24 09:32:36
【问题描述】:

我正在为 iOS 进行 Google+ 登录。

我正在调用类似的身份验证方法

  [signIn authenticate];

我没有使用登录对接。

在这种情况下,验证后不会调用以下方法

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
                   error: (NSError *) error

请告诉我有什么方法可以处理回调吗?

【问题讨论】:

  • 是委托方法吗?
  • 任何解决方案?我有同样的问题..!

标签: ios authentication google-plus


【解决方案1】:

Google+ Sign-In for iOS 说的你有没有按部就班?如果是,那你肯定错过了一个关键步骤。

第 5 步

在您的AppDelegate.m 文件中

#import <GooglePlus/GooglePlus.h>

第 6 步

从您的应用代理的 URL 处理程序调用 GPPURLHandler URL 处理程序。此处理程序将正确处理您的应用程序在身份验证过程结束时收到的 URL。

- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{
    return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}

当您的应用程序在 Google+ OAuth 之后返回时,将调用此方法,并立即调用

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error

你的方法viewController

现在就试试吧。

【讨论】:

  • 否 还是同样的问题:/
  • 我刚刚错过了 appdelegate 的事情。谢谢:-)
  • Vaibhav,你有没有找到这个解决方案?
  • 在我的应用中,我必须同时实现 facebook 和 google 登录,并且我成功实现了。
  • 好吧,你需要在Targets &gt; Info &gt; URL Types创建2个URL Schemes这里是截图s30.postimg.org/kl0tonou9/…
【解决方案2】:

登录后您需要在 viewDidLoad 中执行此操作

signIn.clientID = kClientId;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.shouldFetchGoogleUserID = YES;
signIn.scopes = [NSArray arrayWithObjects:
                 kGTLAuthScopePlusLogin, // defined in GTLPlusConstants.h
                 nil];
signIn.delegate = self;

那么你需要做两个选项之一,但不是两个。

选项1:添加类GPPSignInButton

选项 2:将此 [signIn authenticate]; 添加到某个按钮

然后像这样使用身份验证

- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
               error: (NSError *) error
{
if (error) {
    // Do some error handling here.
} else {
    GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
    plusService.retryEnabled = YES;
    [plusService setAuthorizer:auth];
    GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"];

    [plusService executeQuery:query
            completionHandler:^(GTLServiceTicket *ticket,
                                GTLPlusPerson *person,
                                NSError *error) {
                if (error) {
                    GTMLoggerError(@"Error: %@", error);
                } else {
                    // Retrieve the display name and "about me" text
                    NSString *description = [NSString stringWithFormat:
                                             @"%@\n%@", person.displayName,
                                             person.identifier];

                }
            }];
    }
}

你的 .h 应该是这样的

#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>
#import <GoogleOpenSource/GoogleOpenSource.h>
static NSString * const kClientId = @"yourappnumber.apps.googleusercontent.com";
@interface login : UIViewController<GPPSignInDelegate>
@property (retain, nonatomic) IBOutlet GPPSignInButton *signInButton;
@end

【讨论】:

  • 什么是add the class GPPSignInButton ??
【解决方案3】:

确保您也遵循此步骤

【讨论】:

    【解决方案4】:

    只需添加这个:

    @property (weak, nonatomic) IBOutlet GPPSignInButton *signinButton;
    

    不要担心,如果您没有将它与任何视图链接,只需添加它,它应该可以工作,如果您已经完成了所有步骤。

    【讨论】:

      【解决方案5】:

      这是 Swift 3 中的简单解决方案。

      func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
          if (url.absoluteString.range(of: "oauth2callback") != nil) {
             GPPSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: nil)
          }
         return false
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-10
        • 2023-03-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-29
        相关资源
        最近更新 更多