This repository was archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathreadme.dot
More file actions
59 lines (48 loc) · 1.91 KB
/
readme.dot
File metadata and controls
59 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# TypeScript typings for {{=it.title}} {{=it.version}}
{{=it.description}}
For detailed description please check [documentation]({{=it.documentationLink}}).
## Installing
Install typings for {{=it.title}}:
```
npm install @types/gapi.client.{{=it.name}}@{{=it.version}} --save-dev
```
## Usage
You need to initialize Google API client in your code:
```typescript
gapi.load("client", () => {
// now we can use gapi.client
// ...
});
```
Then load api client wrapper:
```typescript
gapi.client.load('{{=it.name}}', '{{=it.version}}', () => {
// now we can use gapi.client.{{=it.name}}
// ...
});
```
{{? it.auth }}Don't forget to authenticate your client before sending any request to resources:
```typescript
// declare client_id registered in Google Developers Console
var client_id = '',
scope = [ {{ for(var scope in it.auth.oauth2.scopes) { }}
// {{=it.auth.oauth2.scopes[scope].description}}
'{{=scope}}',
{{ } }} ],
immediate = true;
// ...
gapi.auth.authorize({ client_id: client_id, scope: scope, immediate: immediate }, authResult => {
if (authResult && !authResult.error) {
/* handle succesfull authorization */
} else {
/* handle authorization error */
}
});
```{{?}}
After that you can use {{=it.title}} resources:
```typescript{{ for(var resource in it.resources) { }}{{ for(var method in it.resources[resource].methods) { }}
/*
{{=it.resources[resource].methods[method].description}}
*/
await gapi.client.{{=resource}}.{{=method}}({ {{ for(var parameter in it.resources[resource].methods[method].parameters) { }}{{? it.resources[resource].methods[method].parameters[parameter].required }}{{=parameter }}: {{? it.resources[resource].methods[method].parameters[parameter].type === 'integer'}}1{{?}}{{? it.resources[resource].methods[method].parameters[parameter].type === 'string'}}"{{=parameter}}"{{?}}, {{?}}{{ } }} });{{ }}}{{ }}}
```