google-api-client 0.34.1 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +16 -3
  3. data/CHANGELOG.md +114 -0
  4. data/OVERVIEW.md +36 -0
  5. data/README.md +49 -1
  6. data/Rakefile +1 -1
  7. data/docs/api-keys.md +20 -0
  8. data/docs/auth.md +53 -0
  9. data/docs/client-secrets.md +69 -0
  10. data/docs/getting-started.md +340 -0
  11. data/docs/installation.md +0 -0
  12. data/docs/logging.md +34 -0
  13. data/docs/media-upload.md +25 -0
  14. data/docs/oauth-installed.md +191 -0
  15. data/docs/oauth-server.md +135 -0
  16. data/docs/oauth-web.md +280 -0
  17. data/docs/oauth.md +268 -0
  18. data/docs/pagination.md +29 -0
  19. data/docs/performance.md +25 -0
  20. data/generated/google/apis/adexchangebuyer2_v2beta1.rb +1 -1
  21. data/generated/google/apis/adexchangebuyer_v1_3.rb +1 -1
  22. data/generated/google/apis/adexchangebuyer_v1_3/classes.rb +9 -0
  23. data/generated/google/apis/adexchangebuyer_v1_3/representations.rb +1 -0
  24. data/generated/google/apis/adexchangebuyer_v1_4.rb +1 -1
  25. data/generated/google/apis/adexchangebuyer_v1_4/classes.rb +9 -0
  26. data/generated/google/apis/adexchangebuyer_v1_4/representations.rb +1 -0
  27. data/generated/google/apis/androidmanagement_v1.rb +1 -1
  28. data/generated/google/apis/androidpublisher_v3.rb +1 -1
  29. data/generated/google/apis/androidpublisher_v3/classes.rb +93 -0
  30. data/generated/google/apis/androidpublisher_v3/representations.rb +49 -0
  31. data/generated/google/apis/appengine_v1.rb +1 -1
  32. data/generated/google/apis/appengine_v1beta.rb +1 -1
  33. data/generated/google/apis/appsmarket_v2.rb +1 -1
  34. data/generated/google/apis/bigquery_v2.rb +1 -1
  35. data/generated/google/apis/bigquery_v2/classes.rb +46 -4
  36. data/generated/google/apis/bigquery_v2/representations.rb +17 -0
  37. data/generated/google/apis/bigquery_v2/service.rb +1 -5
  38. data/generated/google/apis/bigqueryconnection_v1beta1.rb +1 -1
  39. data/generated/google/apis/bigqueryconnection_v1beta1/classes.rb +6 -5
  40. data/generated/google/apis/bigquerydatatransfer_v1.rb +1 -1
  41. data/generated/google/apis/bigquerydatatransfer_v1/service.rb +30 -4
  42. data/generated/google/apis/bigqueryreservation_v1.rb +1 -1
  43. data/generated/google/apis/bigqueryreservation_v1/classes.rb +0 -21
  44. data/generated/google/apis/bigqueryreservation_v1/representations.rb +0 -13
  45. data/generated/google/apis/bigqueryreservation_v1alpha2.rb +1 -1
  46. data/generated/google/apis/bigqueryreservation_v1alpha2/classes.rb +116 -1
  47. data/generated/google/apis/bigqueryreservation_v1alpha2/representations.rb +35 -0
  48. data/generated/google/apis/bigqueryreservation_v1alpha2/service.rb +71 -0
  49. data/generated/google/apis/bigqueryreservation_v1beta1.rb +1 -1
  50. data/generated/google/apis/bigqueryreservation_v1beta1/classes.rb +61 -77
  51. data/generated/google/apis/bigqueryreservation_v1beta1/representations.rb +16 -17
  52. data/generated/google/apis/bigqueryreservation_v1beta1/service.rb +112 -78
  53. data/generated/google/apis/bigtableadmin_v1.rb +1 -1
  54. data/generated/google/apis/bigtableadmin_v1/classes.rb +1 -1
  55. data/generated/google/apis/bigtableadmin_v2.rb +1 -1
  56. data/generated/google/apis/bigtableadmin_v2/classes.rb +1 -1
  57. data/generated/google/apis/bigtableadmin_v2/service.rb +1 -1
  58. data/generated/google/apis/{sqladmin_v1beta4.rb → billingbudgets_v1beta1.rb} +10 -13
  59. data/generated/google/apis/billingbudgets_v1beta1/classes.rb +392 -0
  60. data/generated/google/apis/billingbudgets_v1beta1/representations.rb +191 -0
  61. data/generated/google/apis/billingbudgets_v1beta1/service.rb +233 -0
  62. data/generated/google/apis/binaryauthorization_v1.rb +1 -1
  63. data/generated/google/apis/binaryauthorization_v1/classes.rb +6 -5
  64. data/generated/google/apis/binaryauthorization_v1beta1.rb +1 -1
  65. data/generated/google/apis/binaryauthorization_v1beta1/classes.rb +6 -5
  66. data/generated/google/apis/books_v1.rb +1 -1
  67. data/generated/google/apis/books_v1/classes.rb +20 -0
  68. data/generated/google/apis/books_v1/representations.rb +3 -0
  69. data/generated/google/apis/calendar_v3.rb +1 -1
  70. data/generated/google/apis/calendar_v3/classes.rb +1 -1
  71. data/generated/google/apis/calendar_v3/service.rb +18 -30
  72. data/generated/google/apis/civicinfo_v2.rb +1 -1
  73. data/generated/google/apis/civicinfo_v2/classes.rb +0 -156
  74. data/generated/google/apis/civicinfo_v2/representations.rb +0 -58
  75. data/generated/google/apis/cloudasset_v1.rb +1 -1
  76. data/generated/google/apis/cloudasset_v1/classes.rb +6 -5
  77. data/generated/google/apis/cloudasset_v1beta1.rb +1 -1
  78. data/generated/google/apis/cloudasset_v1beta1/classes.rb +6 -5
  79. data/generated/google/apis/cloudbilling_v1.rb +1 -1
  80. data/generated/google/apis/cloudbilling_v1/classes.rb +17 -0
  81. data/generated/google/apis/cloudbuild_v1.rb +1 -1
  82. data/generated/google/apis/cloudbuild_v1/classes.rb +8 -2
  83. data/generated/google/apis/cloudbuild_v1/representations.rb +1 -0
  84. data/generated/google/apis/cloudbuild_v1/service.rb +18 -18
  85. data/generated/google/apis/cloudbuild_v1alpha1.rb +1 -1
  86. data/generated/google/apis/cloudbuild_v1alpha1/classes.rb +8 -2
  87. data/generated/google/apis/cloudbuild_v1alpha1/representations.rb +1 -0
  88. data/generated/google/apis/cloudbuild_v1alpha1/service.rb +4 -1
  89. data/generated/google/apis/cloudfunctions_v1.rb +1 -1
  90. data/generated/google/apis/cloudfunctions_v1/classes.rb +13 -5
  91. data/generated/google/apis/cloudfunctions_v1/representations.rb +1 -0
  92. data/generated/google/apis/cloudfunctions_v1/service.rb +3 -1
  93. data/generated/google/apis/cloudiot_v1.rb +1 -1
  94. data/generated/google/apis/cloudiot_v1/classes.rb +6 -5
  95. data/generated/google/apis/cloudkms_v1.rb +1 -1
  96. data/generated/google/apis/cloudkms_v1/classes.rb +6 -5
  97. data/generated/google/apis/cloudprivatecatalogproducer_v1beta1.rb +1 -1
  98. data/generated/google/apis/cloudprivatecatalogproducer_v1beta1/classes.rb +6 -5
  99. data/generated/google/apis/cloudresourcemanager_v1.rb +1 -1
  100. data/generated/google/apis/cloudresourcemanager_v1/classes.rb +6 -5
  101. data/generated/google/apis/cloudresourcemanager_v1beta1.rb +1 -1
  102. data/generated/google/apis/cloudresourcemanager_v1beta1/classes.rb +6 -5
  103. data/generated/google/apis/cloudresourcemanager_v2.rb +1 -1
  104. data/generated/google/apis/cloudresourcemanager_v2/classes.rb +6 -5
  105. data/generated/google/apis/cloudresourcemanager_v2beta1.rb +1 -1
  106. data/generated/google/apis/cloudresourcemanager_v2beta1/classes.rb +6 -5
  107. data/generated/google/apis/cloudscheduler_v1.rb +1 -1
  108. data/generated/google/apis/cloudscheduler_v1/classes.rb +2 -1
  109. data/generated/google/apis/cloudscheduler_v1beta1.rb +1 -1
  110. data/generated/google/apis/cloudscheduler_v1beta1/classes.rb +2 -1
  111. data/generated/google/apis/cloudsearch_v1.rb +8 -8
  112. data/generated/google/apis/cloudsearch_v1/classes.rb +5 -130
  113. data/generated/google/apis/cloudsearch_v1/representations.rb +0 -75
  114. data/generated/google/apis/cloudsearch_v1/service.rb +42 -7
  115. data/generated/google/apis/cloudtasks_v2.rb +1 -1
  116. data/generated/google/apis/cloudtasks_v2/classes.rb +212 -5
  117. data/generated/google/apis/cloudtasks_v2/representations.rb +50 -0
  118. data/generated/google/apis/cloudtasks_v2beta2.rb +1 -1
  119. data/generated/google/apis/cloudtasks_v2beta2/classes.rb +6 -5
  120. data/generated/google/apis/cloudtasks_v2beta3.rb +1 -1
  121. data/generated/google/apis/cloudtasks_v2beta3/classes.rb +6 -5
  122. data/generated/google/apis/commentanalyzer_v1alpha1.rb +1 -1
  123. data/generated/google/apis/commentanalyzer_v1alpha1/classes.rb +14 -19
  124. data/generated/google/apis/compute_alpha.rb +1 -1
  125. data/generated/google/apis/compute_alpha/classes.rb +75 -12
  126. data/generated/google/apis/compute_alpha/representations.rb +2 -0
  127. data/generated/google/apis/compute_beta.rb +1 -1
  128. data/generated/google/apis/compute_beta/classes.rb +54 -10
  129. data/generated/google/apis/compute_v1.rb +1 -1
  130. data/generated/google/apis/compute_v1/classes.rb +54 -10
  131. data/generated/google/apis/containeranalysis_v1alpha1.rb +1 -1
  132. data/generated/google/apis/containeranalysis_v1alpha1/classes.rb +6 -5
  133. data/generated/google/apis/containeranalysis_v1beta1.rb +1 -1
  134. data/generated/google/apis/containeranalysis_v1beta1/classes.rb +6 -5
  135. data/generated/google/apis/content_v2.rb +1 -1
  136. data/generated/google/apis/content_v2/classes.rb +13 -4
  137. data/generated/google/apis/content_v2_1.rb +1 -1
  138. data/generated/google/apis/content_v2_1/classes.rb +13 -4
  139. data/generated/google/apis/datacatalog_v1beta1.rb +35 -0
  140. data/generated/google/apis/datacatalog_v1beta1/classes.rb +1646 -0
  141. data/generated/google/apis/datacatalog_v1beta1/representations.rb +700 -0
  142. data/generated/google/apis/datacatalog_v1beta1/service.rb +1982 -0
  143. data/generated/google/apis/dataproc_v1.rb +1 -1
  144. data/generated/google/apis/dataproc_v1/classes.rb +75 -4
  145. data/generated/google/apis/dataproc_v1/representations.rb +22 -0
  146. data/generated/google/apis/dataproc_v1/service.rb +14 -7
  147. data/generated/google/apis/dataproc_v1beta2.rb +1 -1
  148. data/generated/google/apis/dataproc_v1beta2/classes.rb +2 -4
  149. data/generated/google/apis/dataproc_v1beta2/service.rb +14 -7
  150. data/generated/google/apis/dfareporting_v3_3.rb +1 -1
  151. data/generated/google/apis/dfareporting_v3_3/classes.rb +21 -1
  152. data/generated/google/apis/dfareporting_v3_3/service.rb +6 -6
  153. data/generated/google/apis/dfareporting_v3_4.rb +40 -0
  154. data/generated/google/apis/dfareporting_v3_4/classes.rb +12717 -0
  155. data/generated/google/apis/dfareporting_v3_4/representations.rb +4595 -0
  156. data/generated/google/apis/dfareporting_v3_4/service.rb +8685 -0
  157. data/generated/google/apis/dialogflow_v2.rb +1 -1
  158. data/generated/google/apis/dialogflow_v2/classes.rb +484 -1
  159. data/generated/google/apis/dialogflow_v2/representations.rb +220 -0
  160. data/generated/google/apis/dialogflow_v2beta1.rb +1 -1
  161. data/generated/google/apis/dialogflow_v2beta1/classes.rb +497 -1
  162. data/generated/google/apis/dialogflow_v2beta1/representations.rb +221 -0
  163. data/generated/google/apis/dlp_v2.rb +1 -1
  164. data/generated/google/apis/dlp_v2/classes.rb +68 -25
  165. data/generated/google/apis/dlp_v2/representations.rb +9 -4
  166. data/generated/google/apis/dlp_v2/service.rb +1925 -193
  167. data/generated/google/apis/dns_v1beta2.rb +1 -1
  168. data/generated/google/apis/dns_v1beta2/classes.rb +47 -0
  169. data/generated/google/apis/dns_v1beta2/representations.rb +17 -0
  170. data/generated/google/apis/docs_v1.rb +1 -1
  171. data/generated/google/apis/docs_v1/classes.rb +4 -8
  172. data/generated/google/apis/doubleclickbidmanager_v1.rb +1 -1
  173. data/generated/google/apis/doubleclickbidmanager_v1_1.rb +34 -0
  174. data/generated/google/apis/doubleclickbidmanager_v1_1/classes.rb +826 -0
  175. data/generated/google/apis/doubleclickbidmanager_v1_1/representations.rb +372 -0
  176. data/generated/google/apis/doubleclickbidmanager_v1_1/service.rb +371 -0
  177. data/generated/google/apis/drive_v3.rb +1 -1
  178. data/generated/google/apis/drive_v3/classes.rb +12 -3
  179. data/generated/google/apis/fcm_v1.rb +1 -1
  180. data/generated/google/apis/fcm_v1/classes.rb +15 -0
  181. data/generated/google/apis/fcm_v1/representations.rb +2 -0
  182. data/generated/google/apis/firebase_v1beta1.rb +1 -1
  183. data/generated/google/apis/firebase_v1beta1/classes.rb +3 -4
  184. data/generated/google/apis/firebase_v1beta1/service.rb +6 -6
  185. data/generated/google/apis/firebasehosting_v1beta1.rb +1 -1
  186. data/generated/google/apis/firebasehosting_v1beta1/classes.rb +25 -0
  187. data/generated/google/apis/firebasehosting_v1beta1/representations.rb +15 -0
  188. data/generated/google/apis/firebasehosting_v1beta1/service.rb +47 -0
  189. data/generated/google/apis/firebaserules_v1.rb +1 -1
  190. data/generated/google/apis/firebaserules_v1/classes.rb +26 -0
  191. data/generated/google/apis/firebaserules_v1/representations.rb +15 -0
  192. data/generated/google/apis/genomics_v2alpha1.rb +1 -1
  193. data/generated/google/apis/genomics_v2alpha1/classes.rb +32 -0
  194. data/generated/google/apis/genomics_v2alpha1/representations.rb +16 -0
  195. data/generated/google/apis/healthcare_v1beta1.rb +1 -1
  196. data/generated/google/apis/healthcare_v1beta1/classes.rb +8 -7
  197. data/generated/google/apis/homegraph_v1.rb +1 -1
  198. data/generated/google/apis/homegraph_v1/classes.rb +15 -1
  199. data/generated/google/apis/homegraph_v1/representations.rb +2 -1
  200. data/generated/google/apis/iam_v1.rb +1 -1
  201. data/generated/google/apis/iam_v1/classes.rb +6 -5
  202. data/generated/google/apis/logging_v2.rb +1 -1
  203. data/generated/google/apis/logging_v2/classes.rb +18 -2
  204. data/generated/google/apis/logging_v2/representations.rb +2 -0
  205. data/generated/google/apis/ml_v1.rb +1 -1
  206. data/generated/google/apis/ml_v1/classes.rb +173 -97
  207. data/generated/google/apis/ml_v1/representations.rb +58 -0
  208. data/generated/google/apis/ml_v1/service.rb +37 -0
  209. data/generated/google/apis/monitoring_v3.rb +1 -1
  210. data/generated/google/apis/monitoring_v3/classes.rb +780 -6
  211. data/generated/google/apis/monitoring_v3/representations.rb +347 -0
  212. data/generated/google/apis/monitoring_v3/service.rb +382 -0
  213. data/generated/google/apis/pagespeedonline_v5.rb +1 -1
  214. data/generated/google/apis/pagespeedonline_v5/classes.rb +8 -0
  215. data/generated/google/apis/pagespeedonline_v5/representations.rb +1 -0
  216. data/generated/google/apis/policytroubleshooter_v1beta.rb +1 -1
  217. data/generated/google/apis/policytroubleshooter_v1beta/classes.rb +6 -5
  218. data/generated/google/apis/pubsub_v1.rb +1 -1
  219. data/generated/google/apis/pubsub_v1/classes.rb +8 -6
  220. data/generated/google/apis/pubsub_v1/service.rb +6 -7
  221. data/generated/google/apis/pubsub_v1beta2.rb +1 -1
  222. data/generated/google/apis/pubsub_v1beta2/classes.rb +6 -5
  223. data/generated/google/apis/recommender_v1beta1.rb +1 -1
  224. data/generated/google/apis/recommender_v1beta1/classes.rb +1 -1
  225. data/generated/google/apis/recommender_v1beta1/service.rb +10 -8
  226. data/generated/google/apis/remotebuildexecution_v1.rb +1 -1
  227. data/generated/google/apis/remotebuildexecution_v1/classes.rb +33 -0
  228. data/generated/google/apis/remotebuildexecution_v1/representations.rb +15 -0
  229. data/generated/google/apis/remotebuildexecution_v1alpha.rb +1 -1
  230. data/generated/google/apis/remotebuildexecution_v1alpha/classes.rb +33 -0
  231. data/generated/google/apis/remotebuildexecution_v1alpha/representations.rb +15 -0
  232. data/generated/google/apis/remotebuildexecution_v2.rb +1 -1
  233. data/generated/google/apis/remotebuildexecution_v2/classes.rb +33 -0
  234. data/generated/google/apis/remotebuildexecution_v2/representations.rb +15 -0
  235. data/generated/google/apis/run_v1.rb +1 -1
  236. data/generated/google/apis/run_v1/classes.rb +8 -169
  237. data/generated/google/apis/run_v1/representations.rb +0 -71
  238. data/generated/google/apis/run_v1/service.rb +229 -1207
  239. data/generated/google/apis/run_v1alpha1.rb +1 -1
  240. data/generated/google/apis/run_v1alpha1/classes.rb +9 -9
  241. data/generated/google/apis/runtimeconfig_v1beta1.rb +1 -1
  242. data/generated/google/apis/runtimeconfig_v1beta1/classes.rb +6 -5
  243. data/generated/google/apis/securitycenter_v1.rb +1 -1
  244. data/generated/google/apis/securitycenter_v1/classes.rb +66 -11
  245. data/generated/google/apis/securitycenter_v1/representations.rb +19 -0
  246. data/generated/google/apis/securitycenter_v1beta1.rb +1 -1
  247. data/generated/google/apis/securitycenter_v1beta1/classes.rb +16 -13
  248. data/generated/google/apis/servicebroker_v1.rb +1 -1
  249. data/generated/google/apis/servicebroker_v1/classes.rb +6 -5
  250. data/generated/google/apis/servicebroker_v1alpha1.rb +1 -1
  251. data/generated/google/apis/servicebroker_v1alpha1/classes.rb +6 -5
  252. data/generated/google/apis/servicebroker_v1beta1.rb +1 -1
  253. data/generated/google/apis/servicebroker_v1beta1/classes.rb +6 -5
  254. data/generated/google/apis/serviceconsumermanagement_v1.rb +1 -1
  255. data/generated/google/apis/serviceconsumermanagement_v1/classes.rb +3 -2
  256. data/generated/google/apis/servicecontrol_v1.rb +1 -1
  257. data/generated/google/apis/servicecontrol_v1/classes.rb +8 -1
  258. data/generated/google/apis/servicecontrol_v1/representations.rb +1 -0
  259. data/generated/google/apis/servicemanagement_v1.rb +1 -1
  260. data/generated/google/apis/servicemanagement_v1/classes.rb +12 -9
  261. data/generated/google/apis/servicemanagement_v1/service.rb +1 -9
  262. data/generated/google/apis/servicenetworking_v1.rb +1 -1
  263. data/generated/google/apis/servicenetworking_v1/classes.rb +130 -13
  264. data/generated/google/apis/servicenetworking_v1/representations.rb +58 -0
  265. data/generated/google/apis/servicenetworking_v1/service.rb +42 -3
  266. data/generated/google/apis/servicenetworking_v1beta.rb +1 -1
  267. data/generated/google/apis/servicenetworking_v1beta/classes.rb +3 -2
  268. data/generated/google/apis/serviceusage_v1.rb +1 -1
  269. data/generated/google/apis/serviceusage_v1/classes.rb +3 -2
  270. data/generated/google/apis/serviceusage_v1beta1.rb +1 -1
  271. data/generated/google/apis/serviceusage_v1beta1/classes.rb +3 -2
  272. data/generated/google/apis/sheets_v4.rb +1 -1
  273. data/generated/google/apis/spanner_v1.rb +1 -1
  274. data/generated/google/apis/spanner_v1/classes.rb +70 -30
  275. data/generated/google/apis/spanner_v1/service.rb +270 -0
  276. data/generated/google/apis/speech_v1.rb +1 -1
  277. data/generated/google/apis/speech_v1/classes.rb +6 -0
  278. data/generated/google/apis/speech_v1/representations.rb +1 -0
  279. data/generated/google/apis/speech_v1p1beta1.rb +1 -1
  280. data/generated/google/apis/speech_v1p1beta1/classes.rb +6 -0
  281. data/generated/google/apis/speech_v1p1beta1/representations.rb +1 -0
  282. data/generated/google/apis/sql_v1beta4.rb +1 -1
  283. data/generated/google/apis/sql_v1beta4/service.rb +59 -10
  284. data/generated/google/apis/storagetransfer_v1.rb +1 -1
  285. data/generated/google/apis/videointelligence_v1.rb +1 -1
  286. data/generated/google/apis/videointelligence_v1/classes.rb +112 -0
  287. data/generated/google/apis/videointelligence_v1/representations.rb +62 -0
  288. data/generated/google/apis/videointelligence_v1beta2.rb +1 -1
  289. data/generated/google/apis/videointelligence_v1beta2/classes.rb +112 -0
  290. data/generated/google/apis/videointelligence_v1beta2/representations.rb +62 -0
  291. data/generated/google/apis/videointelligence_v1p1beta1.rb +1 -1
  292. data/generated/google/apis/videointelligence_v1p1beta1/classes.rb +112 -0
  293. data/generated/google/apis/videointelligence_v1p1beta1/representations.rb +62 -0
  294. data/generated/google/apis/videointelligence_v1p2beta1.rb +1 -1
  295. data/generated/google/apis/videointelligence_v1p2beta1/classes.rb +112 -0
  296. data/generated/google/apis/videointelligence_v1p2beta1/representations.rb +62 -0
  297. data/generated/google/apis/videointelligence_v1p3beta1.rb +1 -1
  298. data/generated/google/apis/videointelligence_v1p3beta1/classes.rb +112 -0
  299. data/generated/google/apis/videointelligence_v1p3beta1/representations.rb +62 -0
  300. data/generated/google/apis/youtube_partner_v1.rb +1 -1
  301. data/lib/google/apis/core/api_command.rb +3 -0
  302. data/lib/google/apis/core/http_command.rb +10 -8
  303. data/lib/google/apis/version.rb +1 -1
  304. data/rakelib/devsite/devsite_builder.rb +1 -1
  305. metadata +33 -11
  306. data/generated/google/apis/sqladmin_v1beta4/classes.rb +0 -2633
  307. data/generated/google/apis/sqladmin_v1beta4/representations.rb +0 -1110
  308. data/generated/google/apis/sqladmin_v1beta4/service.rb +0 -1793
  309. data/generated/google/apis/storage_v1beta1.rb +0 -40
  310. data/generated/google/apis/storage_v1beta1/classes.rb +0 -616
  311. data/generated/google/apis/storage_v1beta1/representations.rb +0 -249
  312. data/generated/google/apis/storage_v1beta1/service.rb +0 -1032
File without changes
data/docs/logging.md ADDED
@@ -0,0 +1,34 @@
1
+ # Logging
2
+
3
+ This page provides logging tips to help you debug your applications.
4
+
5
+ ## Accessing the Logger
6
+
7
+ Logging is enabled by default in this library using Ruby's standard Logger class.
8
+
9
+ You can access the library logger with the logger property of Google::Apis.
10
+
11
+ ## Log Level
12
+ You can set the logging level to one of the following:
13
+
14
+ - FATAL (least amount of logging)
15
+ - ERROR
16
+ - WARN
17
+ - INFO
18
+ - DEBUG (most amount of logging)
19
+ In the following code, the logging level is set to DEBUG and the Google Plus API is called:
20
+
21
+ ```rb
22
+ require 'google/apis/plus_v1'
23
+
24
+ Google::Apis.logger.level = Logger::DEBUG
25
+
26
+ plus = Google::Apis::PlusV1::PlusService.new
27
+ activities = plus.list_activities('103354693083460731603', 'public')
28
+ ```
29
+
30
+ The output of this code should include debug info:
31
+
32
+ ```
33
+ D, [2015-06-26T14:33:42.583914 #12144] DEBUG -- : Sending HTTP get https://www.googleapis.com/plus/v1/people/103354693083460731603/activities/public?key=...
34
+ ```
@@ -0,0 +1,25 @@
1
+ ## Media Upload
2
+
3
+ For APIs that support file uploads, two additional keyword parameters are available on the method. The parameter upload_source specifies the content to upload while content_type indicates the MIME type. The upload source may be either a file name, IO, or StringIO instance.
4
+
5
+ For example, to upload a file named 'mymovie.m4v' to Google Drive:
6
+
7
+ ```rb
8
+ require 'google/apis/drive_v2'
9
+
10
+ drive = Google::Apis::DriveV2:DriveService.new
11
+ drive.authorization = ...
12
+ drive.insert_file({title: 'My Favorite Movie'}, upload_source: 'mymovie.m4v',
13
+ content_type: 'video/mp4')
14
+ ```
15
+
16
+ ## Resumable media
17
+
18
+ For large media files, you can use resumable media uploads to send files, which allows files to be uploaded in smaller chunks. This is especially useful if you are transferring large files, and the likelihood of a network interruption or some other transmission failure is high. It can also reduce your bandwidth usage in the event of network failures because you don't have to restart large file uploads from the beginning.
19
+
20
+ To use resumable uploads, enable retries by setting the retry count to any value greater than 0. The client will automatically resume the upload in the event of an error, up to the configured number of retries.:
21
+
22
+ ```rb
23
+ drive.insert_file(file_metadata, upload_source: 'mymovie.m4v',
24
+ content_type: 'video/mp4', options: { retries: 3 } )
25
+ ```
@@ -0,0 +1,191 @@
1
+ # Using OAuth 2.0 for Installed Applications
2
+
3
+ The Google APIs Client Library for Ruby supports using OAuth 2.0 in applications that are installed on a device such as a computer, a cell phone, or a tablet. Installed apps are distributed to individual machines, and it is assumed that these apps cannot keep secrets. These apps might access a Google API while the user is present at the app, or when the app is running in the background.
4
+
5
+ This document is for you if:
6
+
7
+ - You are writing an installed app for a platform other than Android or iOS, and
8
+ - Your installed app will run on devices that have a system browser and rich input capabilities, such as devices with full keyboards.
9
+
10
+ If you are writing an app for Android or iOS, use [Google Sign-In](https://developers.google.com/identity) to authenticate your users. The Google Sign-In button manages the OAuth 2.0 flow both for authentication and for obtaining authorization to Google APIs. To add the Google Sign-In button, follow the steps for [Android](https://developers.google.com/identity/sign-in/android) or [iOS](https://developers.google.com/identity/sign-in/ios).
11
+
12
+ If your app will run on devices that do not have access to a system browser, or devices with limited input capabilities (for example, if your app will run on game consoles, video cameras, or printers), then see [Using OAuth 2.0 for Devices](https://developers.google.com/accounts/docs/OAuth2ForDevices).
13
+
14
+ ## Overview
15
+
16
+ To use OAuth 2.0 in a locally-installed application, first create application credentials for your project in the API Console.
17
+
18
+ Then, when your application needs to access a user's data with a Google API, your application sends the user to Google's OAuth 2.0 server. The OAuth 2.0 server authenticates the user and obtains consent from the user for your application to access the user's data.
19
+
20
+ Next, Google's OAuth 2.0 server sends a single-use authorization code to your application, either in the title bar of the browser or in the query string of an HTTP request to the local host. Your application exchanges this authorization code for an access token.
21
+
22
+ Finally, your application can use the access token to call Google APIs.
23
+
24
+ This flow is similar to the one shown in the [Using OAuth 2.0 for Web Server Applications](docs/oauth-server.md), but with three differences:
25
+
26
+ - When creating a client ID, you specify that your application is an Installed application. This results in a different value for the redirect_uri parameter.
27
+ - The client ID and client secret obtained from the API Console are embedded in the source code of your application. In this context, the client secret is obviously not treated as a secret.
28
+ - The authorization code can be returned to your application in the title bar of the browser or in the query string of an HTTP request to the local host.
29
+
30
+ ## Creating application credentials
31
+
32
+ All applications that use OAuth 2.0 must have credentials that identify the application to the OAuth 2.0 server. Applications that have these credentials can access the APIs that you enabled for your project.
33
+
34
+ To obtain application credentials for your project, complete these steps:
35
+
36
+ 1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the API Console.
37
+ 1. If you haven't done so already, create your OAuth 2.0 credentials by clicking **Create new Client ID** under the **OAuth** heading and selecting the **Installed application** type. Next, look for your application's client ID and client secret in the relevant table.
38
+
39
+ Download the client_secrets.json file and securely store it in a location that only your application can access.
40
+
41
+ > **Important:** Do not store the client_secrets.json file in a publicly-accessible location, and if you share the source code to your application—for example, on GitHub—store the client_secrets.json file outside of your source tree to avoid inadvertently sharing your client credentials.
42
+
43
+ ## Configuring the client object
44
+
45
+ Use the client application credentials that you created to configure a client object in your application. When you configure a client object, you specify the scopes your application needs to access, along with a redirect URI, which will handle the response from the OAuth 2.0 server.
46
+
47
+ ### Choosing a redirect URI
48
+
49
+ When you create a client ID in the [Google API Console](https://console.developers.google.com/), two redirect_uri parameters are created for you: `urn:ietf:wg:oauth:2.0:oob` and `http://localhost`. The value your application uses determines how the authorization code is returned to your application.
50
+
51
+ #### http://localhost
52
+
53
+ This value signals to the Google Authorization Server that the authorization code should be returned as a query string parameter to the web server on the client. You can specify a port number without changing the [Google API Console](https://console.developers.google.com/) configuration. To receive the authorization code using this URI, your application must be listening on the local web server. This is possible on many, but not all, platforms. If your platform supports it, this is the recommended mechanism for obtaining the authorization code.
54
+
55
+ > **Note:** In some cases, although it is possible to listen, other software (such as a Windows firewall) prevents delivery of the message without significant client configuration.
56
+
57
+ #### urn:ietf:wg:oauth:2.0:oob
58
+
59
+ This value signals to the Google Authorization Server that the authorization code should be returned in the title bar of the browser, with the page text prompting the user to copy the code and paste it in the application. This is useful when the client (such as a Windows application) cannot listen on an HTTP port without significant client configuration.
60
+
61
+ When you use this value, your application can then detect that the page has loaded, and can read the title of the HTML page to obtain the authorization code. It is then up to your application to close the browser window if you want to ensure that the user never sees the page that contains the authorization code. The mechanism for doing this varies from platform to platform.
62
+
63
+ If your platform doesn't allow you to detect that the page has loaded or read the title of the page, you can have the user paste the code back to your application, as prompted by the text in the confirmation page that the OAuth 2.0 server generates.
64
+
65
+ #### urn:ietf:wg:oauth:2.0:oob:auto
66
+
67
+ urn:ietf:wg:oauth:2.0:oob:auto
68
+ This is identical to urn:ietf:wg:oauth:2.0:oob, but the text in the confirmation page that the OAuth 2.0 server generates won't instruct the user to copy the authorization code, but instead will simply ask the user to close the window.
69
+
70
+ This is useful when your application reads the title of the HTML page (by checking window titles on the desktop, for example) to obtain the authorization code, but can't close the page on its own.
71
+
72
+ ### Creating the object
73
+
74
+ To create a client object from the client_secrets.json file, use the to_authorization method of a ClientSecrets object. For example, to request read-only access to a user's Google Drive:
75
+
76
+ ```rb
77
+ require 'google/api_client'
78
+
79
+ client_secrets = Google::APIClient::ClientSecrets.load
80
+ auth_client = client_secrets.to_authorization
81
+ auth_client.update!(
82
+ :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
83
+ :redirect_uri => 'urn:ietf:wg:oauth:2.0:oob'
84
+ )
85
+ ```
86
+
87
+ Your application uses the client object to perform OAuth 2.0 operations, such as generating authorization request URIs and applying access tokens to HTTP requests.
88
+
89
+ ## Sending users to Google's OAuth 2.0 server
90
+
91
+ When your application needs to access a user's data, redirect the user to Google's OAuth 2.0 server.
92
+
93
+ 1. Generate a URL to request access from Google's OAuth 2.0 server:
94
+
95
+ `auth_uri = auth_client.authorization_uri.to_s`
96
+
97
+ 2. Open auth_uri in a browser:
98
+
99
+ ```rb
100
+ require 'launchy'
101
+
102
+ Launchy.open(auth_uri)
103
+ ```
104
+
105
+ Google's OAuth 2.0 server will authenticate the user and obtain consent from the user for your application to access the requested scopes. The response will be sent back to your application using the redirect URI specified in the client object.
106
+
107
+ ## Handling the OAuth 2.0 server response
108
+
109
+ The OAuth 2.0 server responds to your application's access request by using the URI specified in the request.
110
+
111
+ If the user approves the access request, then the response contains an authorization code. If the user does not approve the request, the response contains an error message. Depending on the redirect URI that you specified, the response is in the query string of an HTTP request to the local host, or in a web page, from which the user can copy and paste the authorization code.
112
+
113
+ To exchange an authorization code for an access token, use the fetch_access_token! method:
114
+
115
+ ```rb
116
+ auth_client.code = auth_code
117
+ auth_client.fetch_access_token!
118
+ ```
119
+
120
+ ## Calling Google APIs
121
+
122
+ Use the auth_client object to call Google APIs by completing the following steps:
123
+
124
+ 1. Build a service object for the API that you want to call. You build a a service object by calling the discovered_api function with the name and version of the API. For example, to call version 2 of the Drive API:
125
+
126
+ ```rb
127
+ require 'google/apis/drive_v2'
128
+ drive = Google::Apis::DriveV2::DriveService.new
129
+ drive.authorization = auth_client
130
+ ```
131
+
132
+ 2. Make requests to the API service using the interface provided by the service object. For example, to list the files in the authenticated user's Google Drive:
133
+
134
+ ```rb
135
+ files = drive.list_files()
136
+ ```
137
+
138
+ ## Complete example
139
+
140
+ The following example prints a JSON-formatted list of files in a user's Google Drive after the user authenticates and gives consent for the application to access the user's Drive files.
141
+
142
+ ```rb
143
+ require 'google/apis/drive_v2'
144
+ require 'google/api_client/client_secrets'
145
+ require 'launchy'
146
+
147
+ client_secrets = Google::APIClient::ClientSecrets.load
148
+ auth_client = client_secrets.to_authorization
149
+ auth_client.update!(
150
+ :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
151
+ :redirect_uri => 'urn:ietf:wg:oauth:2.0:oob'
152
+ )
153
+
154
+ auth_uri = auth_client.authorization_uri.to_s
155
+ Launchy.open(auth_uri)
156
+
157
+ puts 'Paste the code from the auth response page:'
158
+ auth_client.code = gets
159
+ auth_client.fetch_access_token!
160
+
161
+ drive = Google::Apis::DriveV2::DriveService.new
162
+ drive.authorization = auth_client
163
+ files = drive.list_files
164
+
165
+ files.items.each do |file|
166
+ puts file.title
167
+ end
168
+ ```
169
+
170
+ If you want to use a local web server to handle the OAuth 2.0 response, you can use the InstalledAppFlow helper to simplify the process. For example:
171
+
172
+ ```rb
173
+ require 'google/apis/drive_v2'
174
+ require 'google/api_client/client_secrets'
175
+ require 'google/api_client/auth/installed_app'
176
+
177
+ client_secrets = Google::APIClient::ClientSecrets.load
178
+ flow = Google::APIClient::InstalledAppFlow.new(
179
+ :client_id => client_secrets.client_id,
180
+ :client_secret => client_secrets.client_secret,
181
+ :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
182
+ :port => 5000)
183
+
184
+ drive = Google::Apis::DriveV2::DriveService.new
185
+ drive.authorization = flow.authorize
186
+ files = drive.list_files
187
+
188
+ files.items.each do |file|
189
+ puts file.title
190
+ end
191
+ ```
@@ -0,0 +1,135 @@
1
+ # Using OAuth 2.0 for Server to Server Applications
2
+
3
+ The Google APIs Client Library for Ruby supports using OAuth 2.0 for server-to-server interactions such as those between a web application and a Google service. For this scenario you need a service account, which is an account that belongs to your application instead of to an individual end user. Your application calls Google APIs on behalf of the service account, so users aren't directly involved. This scenario is sometimes called "two-legged OAuth," or "2LO." (The related term "three-legged OAuth" refers to scenarios in which your application calls Google APIs on behalf of end users, and in which user consent is sometimes required.)
4
+
5
+ Typically, an application uses a service account when the application uses Google APIs to work with its own data rather than a user's data. For example, an application that uses [Google Cloud Datastore](https://cloud.google.com/datastore/) for data persistence would use a service account to authenticate its calls to the Google Cloud Datastore API.
6
+
7
+ If you have a G Suite domain—if you use [G Suite](https://gsuite.google.com/), for example—an administrator of the G Suite domain can authorize an application to access user data on behalf of users in the G Suite domain. For example, an application that uses the [Google Calendar API](https://developers.google.com/calendar/) to add events to the calendars of all users in a G Suite domain would use a service account to access the Google Calendar API on behalf of users. Authorizing a service account to access data on behalf of users in a domain is sometimes referred to as "delegating domain-wide authority" to a service account.
8
+
9
+ > **Note:** When you use [G Suite Marketplace](https://www.google.com/enterprise/marketplace/) to install an application for your domain, the required permissions are automatically granted to the application. You do not need to manually authorize the service accounts that the application uses.
10
+
11
+ > **Note:** Although you can use service accounts in applications that run from a Google Apps domain, service accounts are not members of your Google Apps account and aren't subject to domain policies set by Google Apps administrators. For example, a policy set in the Google Apps admin console to restrict the ability of Apps end users to share documents outside of the domain would not apply to service accounts.
12
+
13
+ This document describes how an application can complete the server-to-server OAuth 2.0 flow by using the Google APIs Client Library for Ruby.
14
+
15
+ ## Overview
16
+
17
+ To support server-to-server interactions, first create a service account for your project in the API Console. If you want to access user data for users in your Google Apps domain, then delegate domain-wide access to the service account.
18
+
19
+ Then, your application prepares to make authorized API calls by using the service account's credentials to request an access token from the OAuth 2.0 auth server.
20
+
21
+ Finally, your application can use the access token to call Google APIs.
22
+
23
+ ## Creating a service account
24
+
25
+ A service account's credentials include a generated email address that is unique, a client ID, and at least one public/private key pair.
26
+
27
+ If your application runs on Google App Engine, a service account is set up automatically when you create your project.
28
+
29
+ If your application runs on Google Compute Engine, a service account is also set up automatically when you create your project, but you must specify the scopes that your application needs access to when you create a Google Compute Engine instance. For more information, see [Preparing an instance to use service accounts](https://cloud.google.com/compute/docs/authentication#using).
30
+
31
+ If your application doesn't run on Google App Engine or Google Compute Engine, you must obtain these credentials in the Google API Console. To generate service-account credentials, or to view the public credentials that you've already generated, do the following:
32
+
33
+ 1. Open the [**Service accounts** page](https://console.developers.google.com/permissions/serviceaccounts). If prompted, select a project.
34
+ 1. Click **Create service account**.
35
+ 1. In the **Create service account** window, type a name for the service account, and select **Furnish a new private key**. If you want to [grant G Suite domain-wide authority](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority) to the service account, also select **Enable G Suite Domain-wide Delegation**. Then click **Create**.
36
+
37
+ Your new public/private key pair is generated and downloaded to your machine; it serves as the only copy of this key. You are responsible for storing it securely.
38
+
39
+ You can return to the [API Console](https://console.developers.google.com/) at any time to view the client ID, email address, and public key fingerprints, or to generate additional public/private key pairs. For more details about service account credentials in the API Console, see [Service accounts](https://developers.google.com/console/help/service-accounts) in the API Console help file.
40
+
41
+ Take note of the service account's email address and store the service account's private key file in a location accessible to your application. Your application needs them to make authorized API calls.
42
+
43
+ > **Note:** You must store and manage private keys securely in both development and production environments. Google does not keep a copy of your private keys, only your public keys.
44
+
45
+ ## Delegating domain-wide authority to the service account
46
+
47
+ If your application runs in a Google Apps domain and accesses user data, the service account that you created needs to be granted access to the user data that you want to access.
48
+
49
+ The following steps must be performed by an administrator of the Google Apps domain:
50
+
51
+ 1. Go to your Google Apps domain’s [Admin console](http://admin.google.com/).
52
+ 1. Select **Security** from the list of controls. If you don't see **Security** listed, select **More controls** from the gray bar at the bottom of the page, then select **Security** from the list of controls. If you can't see the controls, make sure you're signed in as an administrator for the domain.
53
+ 1. Select **Advanced settings** from the list of options.
54
+ 1. Select **Manage third party OAuth Client access** in the **Authentication** section.
55
+ 1. In the **Client name** field enter the service account's **Client ID**.
56
+ 1. In the **One or More API Scopes** field enter the list of scopes that your application should be granted access to. For example, if your application needs domain-wide access to the Google Drive API and the Google Calendar API, enter: `https://www.googleapis.com/auth/drive`, `https://www.googleapis.com/auth/calendar`.
57
+ 1. Click **Authorize**.
58
+
59
+ Your application now has the authority to make API calls as users in your domain (to "impersonate" users). When you prepare to make authorized API calls, you specify the user to impersonate.
60
+
61
+ ## Preparing to make an authorized API call
62
+
63
+ After you obtain the client email address and private key from the API Console, complete the following steps:
64
+
65
+ 1. Create a Client object from the service account's credentials and the scopes your application needs access to. For example:
66
+
67
+ ```rb
68
+ require 'googleauth'
69
+ require 'google/apis/compute_v1'
70
+
71
+ compute = Google::Apis::ComputeV1::ComputeService.new
72
+
73
+ # Get the environment configured authorization
74
+ scopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/compute']
75
+ compute.authorization = Google::Auth.get_application_default(scopes)
76
+ ```
77
+
78
+ If you have delegated domain-wide access to the service account and you want to impersonate a user account, specify the email address of the user account in the :sub parameter. For example:
79
+
80
+ ```rb
81
+ require 'googleauth'
82
+ require 'google/apis/sqladmin_v1beta4'
83
+
84
+ # Get the environment configured authorization
85
+ scopes = ['https://www.googleapis.com/auth/sqlservice.admin']
86
+ authorization = Google::Auth.get_application_default(scopes)
87
+
88
+ # Clone and set the subject
89
+ auth_client = authorization.dup
90
+ auth_client.sub = 'user@example.org'
91
+ ```
92
+
93
+ 2. Use the fetch_access_token! method of the client object to acquire an access token. For example:
94
+
95
+ `auth_client.fetch_access_token!`
96
+
97
+ Use the authorized Client object to call Google APIs in your application.
98
+
99
+ ## Calling Google APIs
100
+
101
+ Use the authorized Client object to call Google APIs by completing the following steps:
102
+
103
+ 1. Build a service object for the API that you want to call. You build a a service object by calling the discovered_api method of an APIClient object with the name and version of the API. For example, to call version 1beta3 of the Cloud SQL Administration API:
104
+
105
+ ```rb
106
+
107
+ sqladmin = Google::Apis::SqladminV1beta4::SqladminService.new
108
+ sqladmin.authorization = auth_client
109
+
110
+ Make requests to the API service using the
111
+ interface
112
+ provided by the service object, and providing the authorized
113
+ Client object. For example, to list the instances of Cloud SQL
114
+ databases in the examinable-example-123 project:
115
+
116
+ instances = sqladmin.list_instances('examinable-example-123')
117
+ ```
118
+
119
+ ## Complete example
120
+
121
+ The following example prints a JSON-formatted list of Cloud SQL instances in a project.
122
+
123
+ ```rb
124
+ require 'googleauth'
125
+ require 'google/apis/sqladmin_v1beta4'
126
+
127
+ sqladmin = Google::Apis::SqladminV1beta4::SqladminService.new
128
+
129
+ # Get the environment configured authorization
130
+ scopes = ['https://www.googleapis.com/auth/sqlservice.admin']
131
+ sqladmin.authorization = Google::Auth.get_application_default(scopes)
132
+
133
+ instances = sqladmin.list_instances('examinable-example-123')
134
+ puts instances.to_h
135
+ ```
data/docs/oauth-web.md ADDED
@@ -0,0 +1,280 @@
1
+ # Using OAuth 2.0 for Web Server Applications
2
+
3
+ This document explains how web server applications use the Google API Client Library for Ruby to implement OAuth 2.0 authorization to access Google APIs. OAuth 2.0 allows users to share specific data with an application while keeping their usernames, passwords, and other information private. For example, an application can use OAuth 2.0 to obtain permission from users to store files in their Google Drives.
4
+
5
+ This OAuth 2.0 flow is specifically for user authorization. It is designed for applications that can store confidential information and maintain state. A properly authorized web server application can access an API while the user interacts with the application or after the user has left the application.
6
+
7
+ Web server applications frequently also use [service accounts](service-accounts.md) to authorize API requests, particularly when calling Cloud APIs to access project-based data rather than user-specific data. Web server applications can use service accounts in conjunction with user authorization.
8
+
9
+ ## Prerequisites
10
+
11
+ ### Enable APIs for your project
12
+
13
+ Any application that calls Google APIs needs to enable those APIs in the API Console. To enable the appropriate APIs for your project:
14
+
15
+ 1. Open the [Library](https://console.developers.google.com/apis/library) page in the API Console.
16
+ 1. Select the project associated with your application. Create a project if you do not have one already.
17
+ 1. Use the **Library** page to find each API that your application will use. Click on each API and enable it for your project.
18
+
19
+ ### Create authorization credentials
20
+
21
+ Any application that uses OAuth 2.0 to access Google APIs must have authorization credentials that identify the application to Google's OAuth 2.0 server. The following steps explain how to create credentials for your project. Your applications can then use the credentials to access APIs that you have enabled for that project.
22
+
23
+ <ol>
24
+ <li>Open the <a href="https://console.developers.google.com/apis/credentials">Credentials page</a> in the API Console.</li>
25
+
26
+ <li>Click <b>Create credentials &gt; OAuth client ID</b>.</li>
27
+ <li>Complete the form. Set the application type to <code>Web
28
+ application</code>. Applications that use languages and frameworks
29
+ like PHP, Java, Python, Ruby, and .NET must specify authorized
30
+ <b>redirect URIs</b>. The redirect URIs are the endpoints to which the
31
+ OAuth 2.0 server can send responses.<br><br>
32
+ For testing, you can specify URIs that refer to the local machine,
33
+ such as <code>http://localhost:8080</code>. With that in mind, please
34
+ note that all of the examples in this document use
35
+ <code>http://localhost:8080</code> as the redirect URI.
36
+ <br><br>
37
+ We recommend that you <a href="#protectauthcode">design your app's auth
38
+ endpoints</a> so that your application does not expose authorization
39
+ codes to other resources on the page.</li>
40
+ </ol>
41
+
42
+ After creating your credentials, download the **client_secret.json** file from the API Console. Securely store the file in a location that only your application can access.
43
+
44
+ > **Important:** Do not store the **client_secret.json** file in a publicly-accessible location. In addition, if you share the source code to your application—for example, on GitHub—store the **client_secret.json** file outside of your source tree to avoid inadvertently sharing your client credentials.
45
+
46
+ ### Identify access scopes
47
+
48
+ Scopes enable your application to only request access to the resources that it needs while also enabling users to control the amount of access that they grant to your application. Thus, there may be an inverse relationship between the number of scopes requested and the likelihood of obtaining user consent.
49
+
50
+ Before you start implementing OAuth 2.0 authorization, we recommend that you identify the scopes that your app will need permission to access.
51
+
52
+ We also recommend that your application request access to authorization scopes via an incremental authorization process, in which your application requests access to user data in context. This best practice helps users to more easily understand why your application needs the access it is requesting.
53
+
54
+ The [OAuth 2.0 API Scopes document](https://developers.google.com/identity/protocols/googlescopes) contains a full list of scopes that you might use to access Google APIs.
55
+
56
+ ## Obtaining OAuth 2.0 access tokens
57
+
58
+ The following steps show how your application interacts with Google's OAuth 2.0 server to obtain a user's consent to perform an API request on the user's behalf. Your application must have that consent before it can execute a Google API request that requires user authorization.
59
+
60
+ ### Step 1: Configure the client object
61
+
62
+ Your first step is to configure the client object, which your application uses to obtain user authorization and to make authorized API requests.
63
+
64
+ The client object identifies the scopes that your application is requesting permission to access. These values inform the consent screen that Google displays to the user. The Choosing access scopes section provides information about how to determine which scopes your application should request permission to access.
65
+
66
+ Use the client_secrets.json file that you created to configure a client object in your application. When you configure a client object, you specify the scopes your application needs to access, along with the URL to your application's auth endpoint, which will handle the response from the OAuth 2.0 server.
67
+
68
+ For example, to request read-only, offline access to a user's Google Drive:
69
+
70
+ ```rb
71
+ require 'google/apis/drive_v2'
72
+ require 'google/api_client/client_secrets'
73
+
74
+ client_secrets = Google::APIClient::ClientSecrets.load
75
+ auth_client = client_secrets.to_authorization
76
+ auth_client.update!(
77
+ :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
78
+ :redirect_uri => 'http://www.example.com/oauth2callback',
79
+ :additional_parameters => {
80
+ "access_type" => "offline", # offline access
81
+ "include_granted_scopes" => "true" # incremental auth
82
+ }
83
+ )
84
+ ```
85
+
86
+ Your application uses the client object to perform OAuth 2.0 operations, such as generating authorization request URLs and applying access tokens to HTTP requests.
87
+
88
+ ### Step 2: Redirect to Google's OAuth 2.0 server
89
+
90
+ When your application needs to access a user's data, redirect the user to Google's OAuth 2.0 server.
91
+
92
+ 1. Generate a URL to request access from Google's OAuth 2.0 server:
93
+
94
+ ```rb
95
+ auth_uri = auth_client.authorization_uri.to_s
96
+ ```
97
+
98
+ 2. Redirect the user to auth_uri.
99
+
100
+ Google's OAuth 2.0 server authenticates the user and obtains consent from the user for your application to access the requested scopes. The response is sent back to your application using the redirect URL you specified.
101
+
102
+ ### Step 3: Google prompts user for consent
103
+
104
+ In this step, the user decides whether to grant your application the requested access. At this stage, Google displays a consent window that shows the name of your application and the Google API services that it is requesting permission to access with the user's authorization credentials. The user can then consent or refuse to grant access to your application.
105
+
106
+ Your application doesn't need to do anything at this stage as it waits for the response from Google's OAuth 2.0 server indicating whether the access was granted. That response is explained in the following step.
107
+
108
+ ### Step 4: Handle the OAuth 2.0 server response
109
+
110
+ The OAuth 2.0 server responds to your application's access request by using the URL specified in the request.
111
+
112
+ If the user approves the access request, then the response contains an authorization code. If the user does not approve the request, the response contains an error message. The authorization code or error message that is returned to the web server appears on the query string, as shown below:
113
+
114
+ An error response:
115
+
116
+ ```
117
+ https://oauth2.example.com/auth?error=access_denied
118
+ ```
119
+
120
+ An authorization code response:
121
+
122
+ ```
123
+ https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7
124
+ ```
125
+
126
+ > Important: If your response endpoint renders an HTML page, any resources on that page will be able to see the authorization code in the URL. Scripts can read the URL directly, and the URL in the Referer HTTP header may be sent to any or all resources on the page.
127
+ >
128
+ > Carefully consider whether you want to send authorization credentials to all resources on that page (especially third-party scripts such as social plugins and analytics). To avoid this issue, we recommend that the server first handle the request, then redirect to another URL that doesn't include the response parameters.
129
+
130
+ **Sample OAuth 2.0 server response**
131
+
132
+ You can test this flow by clicking on the following sample URL, which requests read-only access to view metadata for files in your Google Drive:
133
+
134
+ ```
135
+ https://accounts.google.com/o/oauth2/v2/auth?
136
+ scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&
137
+ access_type=offline&
138
+ include_granted_scopes=true&
139
+ state=state_parameter_passthrough_value&
140
+ redirect_uri=http%3A%2F%2Foauth2.example.com%2Fcallback&
141
+ response_type=code&
142
+ client_id=client_id
143
+ ```
144
+
145
+ After completing the OAuth 2.0 flow, you should be redirected to http://localhost/oauth2callback, which will likely yield a 404 NOT FOUND error unless your local machine serves a file at that address. The next step provides more detail about the information returned in the URI when the user is redirected back to your application.
146
+
147
+ ### Step 5: Exchange authorization code for refresh and access tokens
148
+
149
+ After the web server receives the authorization code, it can exchange the authorization code for an access token.
150
+
151
+ To exchange an authorization code for an access token, use the fetch_access_token! method:
152
+
153
+ ```rb
154
+ auth_client.code = auth_code
155
+ auth_client.fetch_access_token!
156
+ ```
157
+
158
+ ## Calling Google APIs
159
+
160
+ Use the auth_client object to call Google APIs by completing the following steps:
161
+
162
+ 1. Build a service object for the API that you want to call. For example, to call version 2 of the Drive API:
163
+ `drive = Google::Apis::DriveV2::DriveService.new`
164
+ 2. Set the credentials on the service:
165
+ `drive.authorization = auth_client`
166
+ 3. Make requests to the API service using the interface provided by the service object. For example, to list the files in the authenticated user's Google Drive:
167
+ `files = drive.list_files`
168
+
169
+ Alternately, authorization can be provided on a per-method basis by supplying the options parameter to a method:
170
+
171
+ `files = drive.list_files(options: { authorization: auth_client })`
172
+
173
+ ## Complete example
174
+
175
+ The following example prints a JSON-formatted list of files in a user's Google Drive after the user authenticates and gives consent for the application to access the user's Drive files.
176
+
177
+ This example uses the Sinatra framework.
178
+
179
+ ```rb
180
+ require 'google/apis/drive_v2'
181
+ require 'google/api_client/client_secrets'
182
+ require 'json'
183
+ require 'sinatra'
184
+
185
+ enable :sessions
186
+ set :session_secret, 'setme'
187
+
188
+ get '/' do
189
+ unless session.has_key?(:credentials)
190
+ redirect to('/oauth2callback')
191
+ end
192
+ client_opts = JSON.parse(session[:credentials])
193
+ auth_client = Signet::OAuth2::Client.new(client_opts)
194
+ drive = Google::Apis::DriveV2::DriveService.new
195
+ files = drive.list_files(options: { authorization: auth_client })
196
+ "<pre>#{JSON.pretty_generate(files.to_h)}</pre>"
197
+ end
198
+
199
+ get '/oauth2callback' do
200
+ client_secrets = Google::APIClient::ClientSecrets.load
201
+ auth_client = client_secrets.to_authorization
202
+ auth_client.update!(
203
+ :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
204
+ :redirect_uri => url('/oauth2callback'))
205
+ if request['code'] == nil
206
+ auth_uri = auth_client.authorization_uri.to_s
207
+ redirect to(auth_uri)
208
+ else
209
+ auth_client.code = request['code']
210
+ auth_client.fetch_access_token!
211
+ auth_client.client_secret = nil
212
+ session[:credentials] = auth_client.to_json
213
+ redirect to('/')
214
+ end
215
+ end
216
+ ```
217
+
218
+ ## Incremental authorization
219
+
220
+ In the OAuth 2.0 protocol, your app requests authorization to access resources, which are identified by scopes. It is considered a best user-experience practice to request authorization for resources at the time you need them. To enable that practice, Google's authorization server supports incremental authorization. This feature lets you request scopes as they are needed and, if the user grants permission, add those scopes to your existing access token for that user.
221
+
222
+ For example, an app that lets people sample music tracks and create mixes might need very few resources at sign-in time, perhaps nothing more than the name of the person signing in. However, saving a completed mix would require access to their Google Drive. Most people would find it natural if they only were asked for access to their Google Drive at the time the app actually needed it.
223
+
224
+ In this case, at sign-in time the app might request the profile scope to perform basic sign-in, and then later request the https://www.googleapis.com/auth/drive.file scope at the time of the first request to save a mix.
225
+
226
+ To implement incremental authorization, you complete the normal flow for requesting an access token but make sure that the authorization request includes previously granted scopes. This approach allows your app to avoid having to manage multiple access tokens.
227
+
228
+ The following rules apply to an access token obtained from an incremental authorization:
229
+
230
+ The token can be used to access resources corresponding to any of the scopes rolled into the new, combined authorization.
231
+ When you use the refresh token for the combined authorization to obtain an access token, the access token represents the combined authorization and can be used for any of its scopes.
232
+ The combined authorization includes all scopes that the user granted to the API project even if the grants were requested from different clients. For example, if a user granted access to one scope using an application's desktop client and then granted another scope to the same application via a mobile client, the combined authorization would include both scopes.
233
+ If you revoke a token that represents a combined authorization, access to all of that authorization's scopes on behalf of the associated user are revoked simultaneously.
234
+ The example for configuring the client object demonstrates how to ensure authorization requests follow this best practice. The code snippet below also shows the code that you need to add to use incremental authorization.
235
+
236
+ ```rb
237
+ auth_client.update!(
238
+ :additional_parameters => {"include_granted_scopes" => "true"}
239
+ )
240
+ ```
241
+
242
+ ## Refreshing an access token (offline access)
243
+
244
+ Access tokens periodically expire. You can refresh an access token without prompting the user for permission (including when the user is not present) if you requested offline access to the scopes associated with the token.
245
+
246
+ If you use a Google API Client Library, the client object refreshes the access token as needed as long as you configure that object for offline access.
247
+
248
+ Requesting offline access is a requirement for any application that needs to access a Google API when the user is not present. For example, an app that performs backup services or executes actions at predetermined times needs to be able to refresh its access token when the user is not present. The default style of access is called online.
249
+
250
+ Server-side web applications, installed applications, and devices all obtain refresh tokens during the authorization process. Refresh tokens are not typically used in client-side (JavaScript) web applications.
251
+
252
+ If your application needs offline access to a Google API, set the API client's access type to offline:
253
+
254
+ ```rb
255
+ auth_client.update!(
256
+ :additional_parameters => {"access_type" => "offline"}
257
+ )
258
+ ```
259
+
260
+ After a user grants offline access to the requested scopes, you can continue to use the API client to access Google APIs on the user's behalf when the user is offline. The client object will refresh the access token as needed.
261
+
262
+ ## Revoking a token
263
+
264
+ In some cases a user may wish to revoke access given to an application. A user can revoke access by visiting Account Settings. It is also possible for an application to programmatically revoke the access given to it. Programmatic revocation is important in instances where a user unsubscribes or removes an application. In other words, part of the removal process can include an API request to ensure the permissions granted to the application are removed.
265
+
266
+ To programmatically revoke a token, make an HTTP request to the oauth2.revoke endpoint:
267
+
268
+ ```rb
269
+ uri = URI('https://accounts.google.com/o/oauth2/revoke')
270
+ params = { :token => auth_client.access_token }
271
+ uri.query = URI.encode_www_form(params)
272
+ response = Net::HTTP.get(uri)
273
+ ```
274
+
275
+ The token can be an access token or a refresh token. If the token is an access token and it has a corresponding refresh token, the refresh token will also be revoked.
276
+
277
+ If the revocation is successfully processed, then the status code of the response is 200. For error conditions, a status code 400 is returned along with an error code.
278
+
279
+ > Note: Following a successful revocation response, it might take some time before the revocation has full effect.
280
+