Lists the user's Team Drives.
#import <CkoRest.h>
#import <CkoOAuth2.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>
CkoRest *rest = [[CkoRest alloc] init];
BOOL success;
// Provide a previously obtained OAuth2 access token.
CkoOAuth2 *oauth2 = [[CkoOAuth2 alloc] init];
oauth2.AccessToken = @"OAUTH2_ACCESS_TOKEN";
[rest SetAuthOAuth2: oauth2];
success = [rest Connect: @"www.googleapis.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
CkoStringBuilder *sbJson = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/drive/v3/teamdrives" sb: sbJson];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d",@"Received error response code: ",[rest.ResponseStatusCode intValue]);
NSLog(@"%@",@"Response body:");
NSLog(@"%@",[sbJson GetAsString]);
return;
}
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json LoadSb: sbJson];
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
NSString *kind = 0;
int i;
int count_i;
NSString *id = 0;
NSString *name = 0;
kind = [json StringOf: @"kind"];
i = 0;
count_i = [[json SizeOfArray: @"teamDrives"] intValue];
while (i < count_i) {
json.I = [NSNumber numberWithInt: i];
kind = [json StringOf: @"teamDrives[i].kind"];
id = [json StringOf: @"teamDrives[i].id"];
name = [json StringOf: @"teamDrives[i].name"];
i = i + 1;
}
NSLog(@"%@",@"Example Completed.");
{
"kind": "drive#teamDriveList",
"teamDrives": [
{
"kind": "drive#teamDrive",
"id": "0AEd3EhGff2SaUk9PVA",
"name": "Project Pegasus"
},
{
"kind": "drive#teamDrive",
"id": "0AGO-j6qTGkqgUk9PVA",
"name": "Project Unicorn"
}
]
}