进行 iOS 授权 Google API 调用

Making an iOS authorised Google API call

我已将 Google 登录集成到我的 iOS 应用程序中,并在登录后检索了访问令牌。我现在想对 [=20] 进行授权 API 调用=],但不确定如何执行此操作以包含令牌。
有人可以分享一些我可以用来包含这个的代码吗?
非常感谢,
卢克

登录并获取令牌后,创建服务实例,然后附加 "authorizer." Google 的 Objective-C 客户端支持相当多的服务:https://code.google.com/p/google-api-objectivec-client/

这是使用 Google+ 的示例:

Obj-C(启用 ARC)

GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
plusService.retryEnabled = YES;

# set an authorizer with your tokens
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];

# submit authenticated queries, assuming your scopes & tokens are legit
GTLQueryPlus *query = [GTLQueryPlus queryForPeopleListWithUserId:@"me"
                                     collection:kGTLPlusCollectionVisible];


[plusService executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLPlusPeopleFeed *peopleFeed,
                            NSError *error) {
               //  ... your callback ...
       }];

Swift

var plusService = GTLServicePlus()
plusService.retryEnabled = true

# set an authorizer with your tokens
plusService.authorizer = GPPSignIn.sharedInstance().authentication

if let plusQuery = GTLQueryPlus.queryForPeopleListWithUserId("me",
                collection: kGTLPlusCollectionVisible) as? GTLPlusQuery {
    // execute the query
    plusService.executeQuery(plusQuery) { (ticket: GTLServiceTicket!,
                                           peopleFeed: GTLPlusPeopleFeed!,
                                           error: NSError!) -> Void in
        // ... your callback ...
    }
}

There is a sample of using the Google Obj-C API client with YouTube specifically. Check out line 229 in YouTubeSampleWindowController.m for setting up your GTLServiceYouTube object, and line 261 用于将它与 GTLQueryYouTube 对象一起使用的示例。

还有一些不错的CocoaDocs. This method可能就是你想要的。

最后 BAHYouTubeOAuth 解决了这个问题,可用 here
我和这个的创建者谈过,他说在更好的令牌处理方面正在发生变化。
如果官方没改过,看看我的修正here