0

iOS用のGoogle+サインインを行っています。

次のような認証方法を呼び出しています

  [signIn authenticate];

私はサインインバッティングを使用していません。

この場合、次のメソッドは認証後に呼び出されません

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

コールバックを処理する方法はありますか?

4

5 に答える 5

10

言われたことを一歩一歩進みましたGoogle+ Sign-In for iOSか?はいの場合、重要なステップを逃したに違いありません。

ステップ 5

あなたのAppDelegate.mファイルで

#import <GooglePlus/GooglePlus.h>

ステップ 6

GPPURLHandlerアプリ デリゲートの URL ハンドラーから 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

今試してみて。

于 2013-10-16T07:31:15.113 に答える
0

サインインでは、viewDidLoadでこれを行う必要があります

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

次に、2 つのオプションのうちの 1 つを実行する必要がありますが、両方を実行する必要はありません。

オプション 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
于 2013-09-05T22:05:05.653 に答える