Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Objective-C) GetHarvest - Test Personal Access TokenDemonstrates how to test your GetHarvest Personal Access Token
#import <CkoHttp.h> #import <CkoStringBuilder.h> #import <CkoJsonObject.h> #import <NSString.h> // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkoHttp *http = [[CkoHttp alloc] init]; BOOL success; [http SetRequestHeader: @"User-Agent" value: @"Harvest API Example"]; [http SetRequestHeader: @"Harvest-Account-ID" value: @"ACCOUNT_ID"]; [http SetRequestHeader: @"Authorization" value: @"Bearer ACCESS_TOKEN"]; CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init]; success = [http QuickGetSb: @"https://api.harvestapp.com/api/v2/users/me.json" sbContent: sbResponseBody]; if (success != YES) { NSLog(@"%@",http.LastErrorText); return; } CkoJsonObject *jResp = [[CkoJsonObject alloc] init]; [jResp LoadSb: sbResponseBody]; jResp.EmitCompact = NO; NSLog(@"%@",@"Response Body:"); NSLog(@"%@",[jResp Emit]); int respStatusCode = [http.LastStatus intValue]; NSLog(@"%@%d",@"Response Status Code = ",respStatusCode); if (respStatusCode >= 400) { NSLog(@"%@",@"Response Header:"); NSLog(@"%@",http.LastResponseHeader); return; } // Sample JSON response: // { // "id": 2826142, // "first_name": "Joe", // "last_name": "Johnson", // "email": "joe@example.com", // "telephone": "", // "timezone": "Central Time (US & Canada)", // "weekly_capacity": 126000, // "has_access_to_all_future_projects": false, // "is_contractor": false, // "is_admin": true, // "is_project_manager": false, // "can_see_rates": true, // "can_create_projects": true, // "can_create_invoices": true, // "is_active": true, // "created_at": "2019-06-06T15:57:58Z", // "updated_at": "2019-06-06T15:58:32Z", // "default_hourly_rate": 175.0, // "cost_rate": 60.0, // "roles": [ // "role1", // "role2" // ], // "avatar_url": "https://d3s3969qhosaug.cloudfront.net/default-avatars/4d46.png?1559836678" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON int id; NSString *first_name = 0; NSString *last_name = 0; NSString *email = 0; NSString *telephone = 0; NSString *timezone = 0; int weekly_capacity; BOOL has_access_to_all_future_projects; BOOL is_contractor; BOOL is_admin; BOOL is_project_manager; BOOL can_see_rates; BOOL can_create_projects; BOOL can_create_invoices; BOOL is_active; NSString *created_at = 0; NSString *updated_at = 0; NSString *default_hourly_rate = 0; NSString *cost_rate = 0; NSString *avatar_url = 0; int i; int count_i; NSString *strVal = 0; id = [[jResp IntOf: @"id"] intValue]; first_name = [jResp StringOf: @"first_name"]; last_name = [jResp StringOf: @"last_name"]; email = [jResp StringOf: @"email"]; telephone = [jResp StringOf: @"telephone"]; timezone = [jResp StringOf: @"timezone"]; weekly_capacity = [[jResp IntOf: @"weekly_capacity"] intValue]; has_access_to_all_future_projects = [jResp BoolOf: @"has_access_to_all_future_projects"]; is_contractor = [jResp BoolOf: @"is_contractor"]; is_admin = [jResp BoolOf: @"is_admin"]; is_project_manager = [jResp BoolOf: @"is_project_manager"]; can_see_rates = [jResp BoolOf: @"can_see_rates"]; can_create_projects = [jResp BoolOf: @"can_create_projects"]; can_create_invoices = [jResp BoolOf: @"can_create_invoices"]; is_active = [jResp BoolOf: @"is_active"]; created_at = [jResp StringOf: @"created_at"]; updated_at = [jResp StringOf: @"updated_at"]; default_hourly_rate = [jResp StringOf: @"default_hourly_rate"]; cost_rate = [jResp StringOf: @"cost_rate"]; avatar_url = [jResp StringOf: @"avatar_url"]; i = 0; count_i = [[jResp SizeOfArray: @"roles"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; strVal = [jResp StringOf: @"roles[i]"]; i = i + 1; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.