You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

889 lines
27 KiB

  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Code generated file. DO NOT EDIT.
  5. // Package oauth2 provides access to the Google OAuth2 API.
  6. //
  7. // For product documentation, see: https://developers.google.com/accounts/docs/OAuth2
  8. //
  9. // Creating a client
  10. //
  11. // Usage example:
  12. //
  13. // import "google.golang.org/api/oauth2/v2"
  14. // ...
  15. // ctx := context.Background()
  16. // oauth2Service, err := oauth2.NewService(ctx)
  17. //
  18. // In this example, Google Application Default Credentials are used for authentication.
  19. //
  20. // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
  21. //
  22. // Other authentication options
  23. //
  24. // By default, all available scopes (see "Constants") are used to authenticate. To restrict scopes, use option.WithScopes:
  25. //
  26. // oauth2Service, err := oauth2.NewService(ctx, option.WithScopes(oauth2.UserinfoProfileScope))
  27. //
  28. // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
  29. //
  30. // oauth2Service, err := oauth2.NewService(ctx, option.WithAPIKey("AIza..."))
  31. //
  32. // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
  33. //
  34. // config := &oauth2.Config{...}
  35. // // ...
  36. // token, err := config.Exchange(ctx, ...)
  37. // oauth2Service, err := oauth2.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
  38. //
  39. // See https://godoc.org/google.golang.org/api/option/ for details on options.
  40. package oauth2 // import "google.golang.org/api/oauth2/v2"
  41. import (
  42. "bytes"
  43. "context"
  44. "encoding/json"
  45. "errors"
  46. "fmt"
  47. "io"
  48. "net/http"
  49. "net/url"
  50. "strconv"
  51. "strings"
  52. gensupport "google.golang.org/api/gensupport"
  53. googleapi "google.golang.org/api/googleapi"
  54. option "google.golang.org/api/option"
  55. htransport "google.golang.org/api/transport/http"
  56. )
  57. // Always reference these packages, just in case the auto-generated code
  58. // below doesn't.
  59. var _ = bytes.NewBuffer
  60. var _ = strconv.Itoa
  61. var _ = fmt.Sprintf
  62. var _ = json.NewDecoder
  63. var _ = io.Copy
  64. var _ = url.Parse
  65. var _ = gensupport.MarshalJSON
  66. var _ = googleapi.Version
  67. var _ = errors.New
  68. var _ = strings.Replace
  69. var _ = context.Canceled
  70. const apiId = "oauth2:v2"
  71. const apiName = "oauth2"
  72. const apiVersion = "v2"
  73. const basePath = "https://www.googleapis.com/"
  74. // OAuth2 scopes used by this API.
  75. const (
  76. // View your basic profile info, including your age range and language
  77. PlusLoginScope = "https://www.googleapis.com/auth/plus.login"
  78. // Know who you are on Google
  79. PlusMeScope = "https://www.googleapis.com/auth/plus.me"
  80. // View your email address
  81. UserinfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
  82. // See your personal info, including any personal info you've made
  83. // publically available
  84. UserinfoProfileScope = "https://www.googleapis.com/auth/userinfo.profile"
  85. )
  86. // NewService creates a new Service.
  87. func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
  88. scopesOption := option.WithScopes(
  89. "https://www.googleapis.com/auth/plus.login",
  90. "https://www.googleapis.com/auth/plus.me",
  91. "https://www.googleapis.com/auth/userinfo.email",
  92. "https://www.googleapis.com/auth/userinfo.profile",
  93. )
  94. // NOTE: prepend, so we don't override user-specified scopes.
  95. opts = append([]option.ClientOption{scopesOption}, opts...)
  96. client, endpoint, err := htransport.NewClient(ctx, opts...)
  97. if err != nil {
  98. return nil, err
  99. }
  100. s, err := New(client)
  101. if err != nil {
  102. return nil, err
  103. }
  104. if endpoint != "" {
  105. s.BasePath = endpoint
  106. }
  107. return s, nil
  108. }
  109. // New creates a new Service. It uses the provided http.Client for requests.
  110. //
  111. // Deprecated: please use NewService instead.
  112. // To provide a custom HTTP client, use option.WithHTTPClient.
  113. // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
  114. func New(client *http.Client) (*Service, error) {
  115. if client == nil {
  116. return nil, errors.New("client is nil")
  117. }
  118. s := &Service{client: client, BasePath: basePath}
  119. s.Userinfo = NewUserinfoService(s)
  120. return s, nil
  121. }
  122. type Service struct {
  123. client *http.Client
  124. BasePath string // API endpoint base URL
  125. UserAgent string // optional additional User-Agent fragment
  126. Userinfo *UserinfoService
  127. }
  128. func (s *Service) userAgent() string {
  129. if s.UserAgent == "" {
  130. return googleapi.UserAgent
  131. }
  132. return googleapi.UserAgent + " " + s.UserAgent
  133. }
  134. func NewUserinfoService(s *Service) *UserinfoService {
  135. rs := &UserinfoService{s: s}
  136. rs.V2 = NewUserinfoV2Service(s)
  137. return rs
  138. }
  139. type UserinfoService struct {
  140. s *Service
  141. V2 *UserinfoV2Service
  142. }
  143. func NewUserinfoV2Service(s *Service) *UserinfoV2Service {
  144. rs := &UserinfoV2Service{s: s}
  145. rs.Me = NewUserinfoV2MeService(s)
  146. return rs
  147. }
  148. type UserinfoV2Service struct {
  149. s *Service
  150. Me *UserinfoV2MeService
  151. }
  152. func NewUserinfoV2MeService(s *Service) *UserinfoV2MeService {
  153. rs := &UserinfoV2MeService{s: s}
  154. return rs
  155. }
  156. type UserinfoV2MeService struct {
  157. s *Service
  158. }
  159. type Jwk struct {
  160. Keys []*JwkKeys `json:"keys,omitempty"`
  161. // ServerResponse contains the HTTP response code and headers from the
  162. // server.
  163. googleapi.ServerResponse `json:"-"`
  164. // ForceSendFields is a list of field names (e.g. "Keys") to
  165. // unconditionally include in API requests. By default, fields with
  166. // empty values are omitted from API requests. However, any non-pointer,
  167. // non-interface field appearing in ForceSendFields will be sent to the
  168. // server regardless of whether the field is empty or not. This may be
  169. // used to include empty fields in Patch requests.
  170. ForceSendFields []string `json:"-"`
  171. // NullFields is a list of field names (e.g. "Keys") to include in API
  172. // requests with the JSON null value. By default, fields with empty
  173. // values are omitted from API requests. However, any field with an
  174. // empty value appearing in NullFields will be sent to the server as
  175. // null. It is an error if a field in this list has a non-empty value.
  176. // This may be used to include null fields in Patch requests.
  177. NullFields []string `json:"-"`
  178. }
  179. func (s *Jwk) MarshalJSON() ([]byte, error) {
  180. type NoMethod Jwk
  181. raw := NoMethod(*s)
  182. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  183. }
  184. type JwkKeys struct {
  185. Alg string `json:"alg,omitempty"`
  186. E string `json:"e,omitempty"`
  187. Kid string `json:"kid,omitempty"`
  188. Kty string `json:"kty,omitempty"`
  189. N string `json:"n,omitempty"`
  190. Use string `json:"use,omitempty"`
  191. // ForceSendFields is a list of field names (e.g. "Alg") to
  192. // unconditionally include in API requests. By default, fields with
  193. // empty values are omitted from API requests. However, any non-pointer,
  194. // non-interface field appearing in ForceSendFields will be sent to the
  195. // server regardless of whether the field is empty or not. This may be
  196. // used to include empty fields in Patch requests.
  197. ForceSendFields []string `json:"-"`
  198. // NullFields is a list of field names (e.g. "Alg") to include in API
  199. // requests with the JSON null value. By default, fields with empty
  200. // values are omitted from API requests. However, any field with an
  201. // empty value appearing in NullFields will be sent to the server as
  202. // null. It is an error if a field in this list has a non-empty value.
  203. // This may be used to include null fields in Patch requests.
  204. NullFields []string `json:"-"`
  205. }
  206. func (s *JwkKeys) MarshalJSON() ([]byte, error) {
  207. type NoMethod JwkKeys
  208. raw := NoMethod(*s)
  209. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  210. }
  211. type Tokeninfo struct {
  212. // AccessType: The access type granted with this token. It can be
  213. // offline or online.
  214. AccessType string `json:"access_type,omitempty"`
  215. // Audience: Who is the intended audience for this token. In general the
  216. // same as issued_to.
  217. Audience string `json:"audience,omitempty"`
  218. // Email: The email address of the user. Present only if the email scope
  219. // is present in the request.
  220. Email string `json:"email,omitempty"`
  221. // ExpiresIn: The expiry time of the token, as number of seconds left
  222. // until expiry.
  223. ExpiresIn int64 `json:"expires_in,omitempty"`
  224. // IssuedTo: To whom was the token issued to. In general the same as
  225. // audience.
  226. IssuedTo string `json:"issued_to,omitempty"`
  227. // Scope: The space separated list of scopes granted to this token.
  228. Scope string `json:"scope,omitempty"`
  229. // TokenHandle: The token handle associated with this token.
  230. TokenHandle string `json:"token_handle,omitempty"`
  231. // UserId: The obfuscated user id.
  232. UserId string `json:"user_id,omitempty"`
  233. // VerifiedEmail: Boolean flag which is true if the email address is
  234. // verified. Present only if the email scope is present in the request.
  235. VerifiedEmail bool `json:"verified_email,omitempty"`
  236. // ServerResponse contains the HTTP response code and headers from the
  237. // server.
  238. googleapi.ServerResponse `json:"-"`
  239. // ForceSendFields is a list of field names (e.g. "AccessType") to
  240. // unconditionally include in API requests. By default, fields with
  241. // empty values are omitted from API requests. However, any non-pointer,
  242. // non-interface field appearing in ForceSendFields will be sent to the
  243. // server regardless of whether the field is empty or not. This may be
  244. // used to include empty fields in Patch requests.
  245. ForceSendFields []string `json:"-"`
  246. // NullFields is a list of field names (e.g. "AccessType") to include in
  247. // API requests with the JSON null value. By default, fields with empty
  248. // values are omitted from API requests. However, any field with an
  249. // empty value appearing in NullFields will be sent to the server as
  250. // null. It is an error if a field in this list has a non-empty value.
  251. // This may be used to include null fields in Patch requests.
  252. NullFields []string `json:"-"`
  253. }
  254. func (s *Tokeninfo) MarshalJSON() ([]byte, error) {
  255. type NoMethod Tokeninfo
  256. raw := NoMethod(*s)
  257. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  258. }
  259. type Userinfoplus struct {
  260. // Email: The user's email address.
  261. Email string `json:"email,omitempty"`
  262. // FamilyName: The user's last name.
  263. FamilyName string `json:"family_name,omitempty"`
  264. // Gender: The user's gender.
  265. Gender string `json:"gender,omitempty"`
  266. // GivenName: The user's first name.
  267. GivenName string `json:"given_name,omitempty"`
  268. // Hd: The hosted domain e.g. example.com if the user is Google apps
  269. // user.
  270. Hd string `json:"hd,omitempty"`
  271. // Id: The obfuscated ID of the user.
  272. Id string `json:"id,omitempty"`
  273. // Link: URL of the profile page.
  274. Link string `json:"link,omitempty"`
  275. // Locale: The user's preferred locale.
  276. Locale string `json:"locale,omitempty"`
  277. // Name: The user's full name.
  278. Name string `json:"name,omitempty"`
  279. // Picture: URL of the user's picture image.
  280. Picture string `json:"picture,omitempty"`
  281. // VerifiedEmail: Boolean flag which is true if the email address is
  282. // verified. Always verified because we only return the user's primary
  283. // email address.
  284. //
  285. // Default: true
  286. VerifiedEmail *bool `json:"verified_email,omitempty"`
  287. // ServerResponse contains the HTTP response code and headers from the
  288. // server.
  289. googleapi.ServerResponse `json:"-"`
  290. // ForceSendFields is a list of field names (e.g. "Email") to
  291. // unconditionally include in API requests. By default, fields with
  292. // empty values are omitted from API requests. However, any non-pointer,
  293. // non-interface field appearing in ForceSendFields will be sent to the
  294. // server regardless of whether the field is empty or not. This may be
  295. // used to include empty fields in Patch requests.
  296. ForceSendFields []string `json:"-"`
  297. // NullFields is a list of field names (e.g. "Email") to include in API
  298. // requests with the JSON null value. By default, fields with empty
  299. // values are omitted from API requests. However, any field with an
  300. // empty value appearing in NullFields will be sent to the server as
  301. // null. It is an error if a field in this list has a non-empty value.
  302. // This may be used to include null fields in Patch requests.
  303. NullFields []string `json:"-"`
  304. }
  305. func (s *Userinfoplus) MarshalJSON() ([]byte, error) {
  306. type NoMethod Userinfoplus
  307. raw := NoMethod(*s)
  308. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  309. }
  310. // method id "oauth2.getCertForOpenIdConnect":
  311. type GetCertForOpenIdConnectCall struct {
  312. s *Service
  313. urlParams_ gensupport.URLParams
  314. ifNoneMatch_ string
  315. ctx_ context.Context
  316. header_ http.Header
  317. }
  318. // GetCertForOpenIdConnect:
  319. func (s *Service) GetCertForOpenIdConnect() *GetCertForOpenIdConnectCall {
  320. c := &GetCertForOpenIdConnectCall{s: s, urlParams_: make(gensupport.URLParams)}
  321. return c
  322. }
  323. // Fields allows partial responses to be retrieved. See
  324. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  325. // for more information.
  326. func (c *GetCertForOpenIdConnectCall) Fields(s ...googleapi.Field) *GetCertForOpenIdConnectCall {
  327. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  328. return c
  329. }
  330. // IfNoneMatch sets the optional parameter which makes the operation
  331. // fail if the object's ETag matches the given value. This is useful for
  332. // getting updates only after the object has changed since the last
  333. // request. Use googleapi.IsNotModified to check whether the response
  334. // error from Do is the result of In-None-Match.
  335. func (c *GetCertForOpenIdConnectCall) IfNoneMatch(entityTag string) *GetCertForOpenIdConnectCall {
  336. c.ifNoneMatch_ = entityTag
  337. return c
  338. }
  339. // Context sets the context to be used in this call's Do method. Any
  340. // pending HTTP request will be aborted if the provided context is
  341. // canceled.
  342. func (c *GetCertForOpenIdConnectCall) Context(ctx context.Context) *GetCertForOpenIdConnectCall {
  343. c.ctx_ = ctx
  344. return c
  345. }
  346. // Header returns an http.Header that can be modified by the caller to
  347. // add HTTP headers to the request.
  348. func (c *GetCertForOpenIdConnectCall) Header() http.Header {
  349. if c.header_ == nil {
  350. c.header_ = make(http.Header)
  351. }
  352. return c.header_
  353. }
  354. func (c *GetCertForOpenIdConnectCall) doRequest(alt string) (*http.Response, error) {
  355. reqHeaders := make(http.Header)
  356. for k, v := range c.header_ {
  357. reqHeaders[k] = v
  358. }
  359. reqHeaders.Set("User-Agent", c.s.userAgent())
  360. if c.ifNoneMatch_ != "" {
  361. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  362. }
  363. var body io.Reader = nil
  364. c.urlParams_.Set("alt", alt)
  365. c.urlParams_.Set("prettyPrint", "false")
  366. urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/certs")
  367. urls += "?" + c.urlParams_.Encode()
  368. req, err := http.NewRequest("GET", urls, body)
  369. if err != nil {
  370. return nil, err
  371. }
  372. req.Header = reqHeaders
  373. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  374. }
  375. // Do executes the "oauth2.getCertForOpenIdConnect" call.
  376. // Exactly one of *Jwk or error will be non-nil. Any non-2xx status code
  377. // is an error. Response headers are in either
  378. // *Jwk.ServerResponse.Header or (if a response was returned at all) in
  379. // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
  380. // whether the returned error was because http.StatusNotModified was
  381. // returned.
  382. func (c *GetCertForOpenIdConnectCall) Do(opts ...googleapi.CallOption) (*Jwk, error) {
  383. gensupport.SetOptions(c.urlParams_, opts...)
  384. res, err := c.doRequest("json")
  385. if res != nil && res.StatusCode == http.StatusNotModified {
  386. if res.Body != nil {
  387. res.Body.Close()
  388. }
  389. return nil, &googleapi.Error{
  390. Code: res.StatusCode,
  391. Header: res.Header,
  392. }
  393. }
  394. if err != nil {
  395. return nil, err
  396. }
  397. defer googleapi.CloseBody(res)
  398. if err := googleapi.CheckResponse(res); err != nil {
  399. return nil, err
  400. }
  401. ret := &Jwk{
  402. ServerResponse: googleapi.ServerResponse{
  403. Header: res.Header,
  404. HTTPStatusCode: res.StatusCode,
  405. },
  406. }
  407. target := &ret
  408. if err := gensupport.DecodeResponse(target, res); err != nil {
  409. return nil, err
  410. }
  411. return ret, nil
  412. // {
  413. // "httpMethod": "GET",
  414. // "id": "oauth2.getCertForOpenIdConnect",
  415. // "path": "oauth2/v2/certs",
  416. // "response": {
  417. // "$ref": "Jwk"
  418. // }
  419. // }
  420. }
  421. // method id "oauth2.tokeninfo":
  422. type TokeninfoCall struct {
  423. s *Service
  424. urlParams_ gensupport.URLParams
  425. ctx_ context.Context
  426. header_ http.Header
  427. }
  428. // Tokeninfo:
  429. func (s *Service) Tokeninfo() *TokeninfoCall {
  430. c := &TokeninfoCall{s: s, urlParams_: make(gensupport.URLParams)}
  431. return c
  432. }
  433. // AccessToken sets the optional parameter "access_token":
  434. func (c *TokeninfoCall) AccessToken(accessToken string) *TokeninfoCall {
  435. c.urlParams_.Set("access_token", accessToken)
  436. return c
  437. }
  438. // IdToken sets the optional parameter "id_token":
  439. func (c *TokeninfoCall) IdToken(idToken string) *TokeninfoCall {
  440. c.urlParams_.Set("id_token", idToken)
  441. return c
  442. }
  443. // TokenHandle sets the optional parameter "token_handle":
  444. func (c *TokeninfoCall) TokenHandle(tokenHandle string) *TokeninfoCall {
  445. c.urlParams_.Set("token_handle", tokenHandle)
  446. return c
  447. }
  448. // Fields allows partial responses to be retrieved. See
  449. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  450. // for more information.
  451. func (c *TokeninfoCall) Fields(s ...googleapi.Field) *TokeninfoCall {
  452. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  453. return c
  454. }
  455. // Context sets the context to be used in this call's Do method. Any
  456. // pending HTTP request will be aborted if the provided context is
  457. // canceled.
  458. func (c *TokeninfoCall) Context(ctx context.Context) *TokeninfoCall {
  459. c.ctx_ = ctx
  460. return c
  461. }
  462. // Header returns an http.Header that can be modified by the caller to
  463. // add HTTP headers to the request.
  464. func (c *TokeninfoCall) Header() http.Header {
  465. if c.header_ == nil {
  466. c.header_ = make(http.Header)
  467. }
  468. return c.header_
  469. }
  470. func (c *TokeninfoCall) doRequest(alt string) (*http.Response, error) {
  471. reqHeaders := make(http.Header)
  472. for k, v := range c.header_ {
  473. reqHeaders[k] = v
  474. }
  475. reqHeaders.Set("User-Agent", c.s.userAgent())
  476. var body io.Reader = nil
  477. c.urlParams_.Set("alt", alt)
  478. c.urlParams_.Set("prettyPrint", "false")
  479. urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/tokeninfo")
  480. urls += "?" + c.urlParams_.Encode()
  481. req, err := http.NewRequest("POST", urls, body)
  482. if err != nil {
  483. return nil, err
  484. }
  485. req.Header = reqHeaders
  486. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  487. }
  488. // Do executes the "oauth2.tokeninfo" call.
  489. // Exactly one of *Tokeninfo or error will be non-nil. Any non-2xx
  490. // status code is an error. Response headers are in either
  491. // *Tokeninfo.ServerResponse.Header or (if a response was returned at
  492. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  493. // to check whether the returned error was because
  494. // http.StatusNotModified was returned.
  495. func (c *TokeninfoCall) Do(opts ...googleapi.CallOption) (*Tokeninfo, error) {
  496. gensupport.SetOptions(c.urlParams_, opts...)
  497. res, err := c.doRequest("json")
  498. if res != nil && res.StatusCode == http.StatusNotModified {
  499. if res.Body != nil {
  500. res.Body.Close()
  501. }
  502. return nil, &googleapi.Error{
  503. Code: res.StatusCode,
  504. Header: res.Header,
  505. }
  506. }
  507. if err != nil {
  508. return nil, err
  509. }
  510. defer googleapi.CloseBody(res)
  511. if err := googleapi.CheckResponse(res); err != nil {
  512. return nil, err
  513. }
  514. ret := &Tokeninfo{
  515. ServerResponse: googleapi.ServerResponse{
  516. Header: res.Header,
  517. HTTPStatusCode: res.StatusCode,
  518. },
  519. }
  520. target := &ret
  521. if err := gensupport.DecodeResponse(target, res); err != nil {
  522. return nil, err
  523. }
  524. return ret, nil
  525. // {
  526. // "httpMethod": "POST",
  527. // "id": "oauth2.tokeninfo",
  528. // "parameters": {
  529. // "access_token": {
  530. // "location": "query",
  531. // "type": "string"
  532. // },
  533. // "id_token": {
  534. // "location": "query",
  535. // "type": "string"
  536. // },
  537. // "token_handle": {
  538. // "location": "query",
  539. // "type": "string"
  540. // }
  541. // },
  542. // "path": "oauth2/v2/tokeninfo",
  543. // "response": {
  544. // "$ref": "Tokeninfo"
  545. // }
  546. // }
  547. }
  548. // method id "oauth2.userinfo.get":
  549. type UserinfoGetCall struct {
  550. s *Service
  551. urlParams_ gensupport.URLParams
  552. ifNoneMatch_ string
  553. ctx_ context.Context
  554. header_ http.Header
  555. }
  556. // Get:
  557. func (r *UserinfoService) Get() *UserinfoGetCall {
  558. c := &UserinfoGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  559. return c
  560. }
  561. // Fields allows partial responses to be retrieved. See
  562. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  563. // for more information.
  564. func (c *UserinfoGetCall) Fields(s ...googleapi.Field) *UserinfoGetCall {
  565. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  566. return c
  567. }
  568. // IfNoneMatch sets the optional parameter which makes the operation
  569. // fail if the object's ETag matches the given value. This is useful for
  570. // getting updates only after the object has changed since the last
  571. // request. Use googleapi.IsNotModified to check whether the response
  572. // error from Do is the result of In-None-Match.
  573. func (c *UserinfoGetCall) IfNoneMatch(entityTag string) *UserinfoGetCall {
  574. c.ifNoneMatch_ = entityTag
  575. return c
  576. }
  577. // Context sets the context to be used in this call's Do method. Any
  578. // pending HTTP request will be aborted if the provided context is
  579. // canceled.
  580. func (c *UserinfoGetCall) Context(ctx context.Context) *UserinfoGetCall {
  581. c.ctx_ = ctx
  582. return c
  583. }
  584. // Header returns an http.Header that can be modified by the caller to
  585. // add HTTP headers to the request.
  586. func (c *UserinfoGetCall) Header() http.Header {
  587. if c.header_ == nil {
  588. c.header_ = make(http.Header)
  589. }
  590. return c.header_
  591. }
  592. func (c *UserinfoGetCall) doRequest(alt string) (*http.Response, error) {
  593. reqHeaders := make(http.Header)
  594. for k, v := range c.header_ {
  595. reqHeaders[k] = v
  596. }
  597. reqHeaders.Set("User-Agent", c.s.userAgent())
  598. if c.ifNoneMatch_ != "" {
  599. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  600. }
  601. var body io.Reader = nil
  602. c.urlParams_.Set("alt", alt)
  603. c.urlParams_.Set("prettyPrint", "false")
  604. urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/userinfo")
  605. urls += "?" + c.urlParams_.Encode()
  606. req, err := http.NewRequest("GET", urls, body)
  607. if err != nil {
  608. return nil, err
  609. }
  610. req.Header = reqHeaders
  611. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  612. }
  613. // Do executes the "oauth2.userinfo.get" call.
  614. // Exactly one of *Userinfoplus or error will be non-nil. Any non-2xx
  615. // status code is an error. Response headers are in either
  616. // *Userinfoplus.ServerResponse.Header or (if a response was returned at
  617. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  618. // to check whether the returned error was because
  619. // http.StatusNotModified was returned.
  620. func (c *UserinfoGetCall) Do(opts ...googleapi.CallOption) (*Userinfoplus, error) {
  621. gensupport.SetOptions(c.urlParams_, opts...)
  622. res, err := c.doRequest("json")
  623. if res != nil && res.StatusCode == http.StatusNotModified {
  624. if res.Body != nil {
  625. res.Body.Close()
  626. }
  627. return nil, &googleapi.Error{
  628. Code: res.StatusCode,
  629. Header: res.Header,
  630. }
  631. }
  632. if err != nil {
  633. return nil, err
  634. }
  635. defer googleapi.CloseBody(res)
  636. if err := googleapi.CheckResponse(res); err != nil {
  637. return nil, err
  638. }
  639. ret := &Userinfoplus{
  640. ServerResponse: googleapi.ServerResponse{
  641. Header: res.Header,
  642. HTTPStatusCode: res.StatusCode,
  643. },
  644. }
  645. target := &ret
  646. if err := gensupport.DecodeResponse(target, res); err != nil {
  647. return nil, err
  648. }
  649. return ret, nil
  650. // {
  651. // "httpMethod": "GET",
  652. // "id": "oauth2.userinfo.get",
  653. // "path": "oauth2/v2/userinfo",
  654. // "response": {
  655. // "$ref": "Userinfoplus"
  656. // },
  657. // "scopes": [
  658. // "https://www.googleapis.com/auth/plus.login",
  659. // "https://www.googleapis.com/auth/plus.me",
  660. // "https://www.googleapis.com/auth/userinfo.email",
  661. // "https://www.googleapis.com/auth/userinfo.profile"
  662. // ]
  663. // }
  664. }
  665. // method id "oauth2.userinfo.v2.me.get":
  666. type UserinfoV2MeGetCall struct {
  667. s *Service
  668. urlParams_ gensupport.URLParams
  669. ifNoneMatch_ string
  670. ctx_ context.Context
  671. header_ http.Header
  672. }
  673. // Get:
  674. func (r *UserinfoV2MeService) Get() *UserinfoV2MeGetCall {
  675. c := &UserinfoV2MeGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  676. return c
  677. }
  678. // Fields allows partial responses to be retrieved. See
  679. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  680. // for more information.
  681. func (c *UserinfoV2MeGetCall) Fields(s ...googleapi.Field) *UserinfoV2MeGetCall {
  682. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  683. return c
  684. }
  685. // IfNoneMatch sets the optional parameter which makes the operation
  686. // fail if the object's ETag matches the given value. This is useful for
  687. // getting updates only after the object has changed since the last
  688. // request. Use googleapi.IsNotModified to check whether the response
  689. // error from Do is the result of In-None-Match.
  690. func (c *UserinfoV2MeGetCall) IfNoneMatch(entityTag string) *UserinfoV2MeGetCall {
  691. c.ifNoneMatch_ = entityTag
  692. return c
  693. }
  694. // Context sets the context to be used in this call's Do method. Any
  695. // pending HTTP request will be aborted if the provided context is
  696. // canceled.
  697. func (c *UserinfoV2MeGetCall) Context(ctx context.Context) *UserinfoV2MeGetCall {
  698. c.ctx_ = ctx
  699. return c
  700. }
  701. // Header returns an http.Header that can be modified by the caller to
  702. // add HTTP headers to the request.
  703. func (c *UserinfoV2MeGetCall) Header() http.Header {
  704. if c.header_ == nil {
  705. c.header_ = make(http.Header)
  706. }
  707. return c.header_
  708. }
  709. func (c *UserinfoV2MeGetCall) doRequest(alt string) (*http.Response, error) {
  710. reqHeaders := make(http.Header)
  711. for k, v := range c.header_ {
  712. reqHeaders[k] = v
  713. }
  714. reqHeaders.Set("User-Agent", c.s.userAgent())
  715. if c.ifNoneMatch_ != "" {
  716. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  717. }
  718. var body io.Reader = nil
  719. c.urlParams_.Set("alt", alt)
  720. c.urlParams_.Set("prettyPrint", "false")
  721. urls := googleapi.ResolveRelative(c.s.BasePath, "userinfo/v2/me")
  722. urls += "?" + c.urlParams_.Encode()
  723. req, err := http.NewRequest("GET", urls, body)
  724. if err != nil {
  725. return nil, err
  726. }
  727. req.Header = reqHeaders
  728. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  729. }
  730. // Do executes the "oauth2.userinfo.v2.me.get" call.
  731. // Exactly one of *Userinfoplus or error will be non-nil. Any non-2xx
  732. // status code is an error. Response headers are in either
  733. // *Userinfoplus.ServerResponse.Header or (if a response was returned at
  734. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  735. // to check whether the returned error was because
  736. // http.StatusNotModified was returned.
  737. func (c *UserinfoV2MeGetCall) Do(opts ...googleapi.CallOption) (*Userinfoplus, error) {
  738. gensupport.SetOptions(c.urlParams_, opts...)
  739. res, err := c.doRequest("json")
  740. if res != nil && res.StatusCode == http.StatusNotModified {
  741. if res.Body != nil {
  742. res.Body.Close()
  743. }
  744. return nil, &googleapi.Error{
  745. Code: res.StatusCode,
  746. Header: res.Header,
  747. }
  748. }
  749. if err != nil {
  750. return nil, err
  751. }
  752. defer googleapi.CloseBody(res)
  753. if err := googleapi.CheckResponse(res); err != nil {
  754. return nil, err
  755. }
  756. ret := &Userinfoplus{
  757. ServerResponse: googleapi.ServerResponse{
  758. Header: res.Header,
  759. HTTPStatusCode: res.StatusCode,
  760. },
  761. }
  762. target := &ret
  763. if err := gensupport.DecodeResponse(target, res); err != nil {
  764. return nil, err
  765. }
  766. return ret, nil
  767. // {
  768. // "httpMethod": "GET",
  769. // "id": "oauth2.userinfo.v2.me.get",
  770. // "path": "userinfo/v2/me",
  771. // "response": {
  772. // "$ref": "Userinfoplus"
  773. // },
  774. // "scopes": [
  775. // "https://www.googleapis.com/auth/plus.login",
  776. // "https://www.googleapis.com/auth/plus.me",
  777. // "https://www.googleapis.com/auth/userinfo.email",
  778. // "https://www.googleapis.com/auth/userinfo.profile"
  779. // ]
  780. // }
  781. }