Cria token bearer de autenticação
curl --request POST \
--url https://api.google.com/api:XUynQtIz/api/v{version}/auth/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=70000006 \
--data client_secret=password \
--data expires_in=100import requests
url = "https://api.google.com/api:XUynQtIz/api/v{version}/auth/token"
payload = {
"grant_type": "client_credentials",
"client_id": "70000006",
"client_secret": "password",
"expires_in": "100"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: '70000006',
client_secret: 'password',
expires_in: '100'
})
};
fetch('https://api.google.com/api:XUynQtIz/api/v{version}/auth/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.google.com/api:XUynQtIz/api/v{version}/auth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100",
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.google.com/api:XUynQtIz/api/v{version}/auth/token"
payload := strings.NewReader("grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.google.com/api:XUynQtIz/api/v{version}/auth/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.google.com/api:XUynQtIz/api/v{version}/auth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100"
response = http.request(request)
puts response.read_body{
"token_type": "bearer",
"expires_in": 604800,
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Auth
Criar código token para autenticação
POST
/
api
/
v
{version}
/
auth
/
token
Cria token bearer de autenticação
curl --request POST \
--url https://api.google.com/api:XUynQtIz/api/v{version}/auth/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=70000006 \
--data client_secret=password \
--data expires_in=100import requests
url = "https://api.google.com/api:XUynQtIz/api/v{version}/auth/token"
payload = {
"grant_type": "client_credentials",
"client_id": "70000006",
"client_secret": "password",
"expires_in": "100"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: '70000006',
client_secret: 'password',
expires_in: '100'
})
};
fetch('https://api.google.com/api:XUynQtIz/api/v{version}/auth/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.google.com/api:XUynQtIz/api/v{version}/auth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100",
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.google.com/api:XUynQtIz/api/v{version}/auth/token"
payload := strings.NewReader("grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.google.com/api:XUynQtIz/api/v{version}/auth/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.google.com/api:XUynQtIz/api/v{version}/auth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=client_credentials&client_id=70000006&client_secret=password&expires_in=100"
response = http.request(request)
puts response.read_body{
"token_type": "bearer",
"expires_in": 604800,
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Path Parameters
Body
application/x-www-form-urlencoded
Deve ser definido como client_credentials
Example:
"client_credentials"
ID de acesso do usuário
Example:
"70000006"
Senha do usuário
Example:
"password"
Tempo de expiração do token em segundos. Se não informado, o serviço web usará o valor padrão de 7 dias.
Example:
100
Response
Token bearer
Indica o tipo de token. O único tipo suportado é bearer.
Example:
"bearer"
Quantidade de tempo em que o token de acesso é válido (em segundos).
Example:
31536000
O token de acesso solicitado.
Example:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjcwMDAwMDAxIiwicm9sZSI6IlByb3Zpc2lvbmluZyIsIm5iZiI6MTY4NTAyNjU2NSwiZXhwIjoxNjg1NjMxMzY1LCJpYXQiOjE2ODUwMjY1NjUsImlzcyI6IlNlY3VyZUFwaSIsImF1ZCI6IlNlY3VyZUFwaVVzZXIifQ.n-bCYU0ooHE6vR3dsWvXRUXHNK6Rt_QR8PpNIOoX4bY"
Uma string de código de erro
Example:
"unauthorized_client"

