如何在iOS中实施谷歌硬盘?

时间:2018-05-31 05:56:28

标签: ios objective-c google-drive-api

iOS中的Im元素谷歌驱动器显示错误

  

无法完成操作(com.google.GIDSignin错误 - 4。)

下的

- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error

我在下面的代码中添加了从textField

备份谷歌驱动器中的内容
GIDSignIn* signIn = [GIDSignIn sharedInstance];
signIn.delegate = self;
signIn.uiDelegate = self;
signIn.scopes = [NSArray arrayWithObjects:kGTLRAuthScopeDriveReadonly, nil];
[signIn signInSilently];

// Add the sign-in button.
self.signInButton = [[GIDSignInButton alloc] init];
[self.view addSubview:self.signInButton];

// Create a UITextView to display output.
self.output = [[UITextView alloc] initWithFrame:self.view.bounds];
self.output.editable = false;
self.output.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0);
self.output.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.output.hidden = true;
[self.view addSubview:self.output];

// Initialize the service object.
self.service = [[GTLRDriveService alloc] init];

1 个答案:

答案 0 :(得分:0)

错误表示钥匙串中没有身份验证令牌,即“用户未经授权”。

要检查用户是否获得授权,请使用以下代码:

func checkIfUserIsAuthorized() {
    if GIDSignIn.sharedInstance().hasAuthInKeychain() {
        // User authorized before
        GIDSignIn.sharedInstance().signInSilently()
    } else {
        // User not authorized open sign in screen

    }
}