Creating an Authorized Google API for iOS
2 answers
After you've logged in and purchased tokens, you create service instances and then attach an "authorizer". The Google Objective-C client supports multiple services: https://code.google.com/p/google-api-objectivec-client/
Here's an example using Google +:
Obj-C (with ARC support)
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 an example using the Google Obj-C API from YouTube. Mark the line 229 in YouTubeSampleWindowController.m
to customize your object GTLServiceYouTube
and line 261 for an example of using it with an object GTLQueryYouTube
.
There are also some nice CocoaDocs . This method is probably what you need.
+2
source to share