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.
 
 
 

810 lines
24 KiB

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