【发布时间】:2017-01-13 08:39:57
【问题描述】:
我想在我的 iOS 应用中集成 Google Drive。
我已经完成了授权代码,并且我正在取回 accessToken,所以我想知道 - 从 Google Drive 中检索 PDF 文件到哪里去。
我的登录密码:
- (IBAction)signInButtonTapped:(id)sender {
NSURL *issuer = [NSURL URLWithString:kIssuer];
NSURL *redirectURI = [NSURL URLWithString:kRedirectURI];
[self logMessage:@"Fetching configuration for issuer: %@", issuer];
// discovers endpoints
[OIDAuthorizationService discoverServiceConfigurationForIssuer:issuer
completion:^(OIDServiceConfiguration *_Nullable configuration, NSError *_Nullable error) {
if (!configuration) {
[self logMessage:@"Error retrieving discovery document: %@", [error localizedDescription]];
[self setAuthState:nil];
return;
}
[self logMessage:@"Got configuration: %@", configuration];
// builds authentication request
OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
clientId:kClientID
scopes:@[OIDScopeOpenID, OIDScopeProfile]
redirectURL:redirectURI
responseType:OIDResponseTypeCode
additionalParameters:nil];
// performs authentication request
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[self logMessage:@"Initiating authorization request with scope: %@", request.scope];
appDelegate.currentAuthorizationFlow =
[OIDAuthState authStateByPresentingAuthorizationRequest:request
presentingViewController:self
callback:^(OIDAuthState *_Nullable authState,
NSError *_Nullable error) {
if (authState) {
[self setAuthState:authState];
[self logMessage:@"Got authorization tokens. Access token: %@", authState.lastTokenResponse.accessToken];
[self logMessage:@"Got authorization tokens. Refresh Access token %@", authState.refreshToken];
} else {
[self logMessage:@"Authorization error: %@", [error localizedDescription]];
[self setAuthState:nil];
}
}];}];}
【问题讨论】:
-
您可能需要检查Downloading Google Documents。给定的示例演示了如何使用客户端库下载 PDF 格式的 Google 文档。您还可以查看支持的导出 MIME 类型表以获取每种 Google Doc 格式的相应 MIME 类型。如需更详细的信息,您可能需要查看full iOS documentation。
-
@Sipho Koza,什么 url 需要设置为 redirectURI?我被困在这里,它是否也需要添加到开发者控制台?请帮忙。
-
我写了一个中型博客,一步一步解释。看看这个medium.com/@kunalgupta1508/…
标签: objective-c google-drive-api