Log in
curl --request POST \
--url https://api.4casters.io/user/login \
--header 'Content-Type: application/json' \
--data '
{
"username": "your_username",
"password": "your_password"
}
'import requests
url = "https://api.4casters.io/user/login"
payload = {
"username": "your_username",
"password": "your_password"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({username: 'your_username', password: 'your_password'})
};
fetch('https://api.4casters.io/user/login', 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.4casters.io/user/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'username' => 'your_username',
'password' => 'your_password'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.4casters.io/user/login"
payload := strings.NewReader("{\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
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.4casters.io/user/login")
.header("Content-Type", "application/json")
.body("{\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.4casters.io/user/login")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"user": {
"id": "<string>",
"username": "<string>",
"type": "free",
"oddsFormat": "american",
"displayBalance": 123,
"creditLimit": 123,
"liability": 123,
"commissionCharged": 123,
"maxLiability": 123,
"matchedVolume": {},
"openInterest": {},
"isAdmin": true,
"hasMarketMakerAccess": true,
"isPro": true,
"isDeposit": true,
"isAlphaUser": true,
"sportsbookDefault": true,
"defaultRotationNumbers": true,
"displayRotationNumbers": true,
"viewOddsWithCommission": true,
"defaultExpiry": 123,
"defaultOffer": 123,
"defaultSendOrderMessage": true,
"sportsbookMinimumDisplay": 123,
"showChatLastMessage": true,
"yesNoSummary": true,
"accessCode": "<string>",
"code": "<string>",
"p2pCode": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"emailConfirmation": true,
"auth": "<string>",
"email": "[email protected]",
"passwordSecurityChecks": {}
}
}
}{
"error": "<string>"
}入门
认证
登录并为请求授权
POST
/
user
/
login
Log in
curl --request POST \
--url https://api.4casters.io/user/login \
--header 'Content-Type: application/json' \
--data '
{
"username": "your_username",
"password": "your_password"
}
'import requests
url = "https://api.4casters.io/user/login"
payload = {
"username": "your_username",
"password": "your_password"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({username: 'your_username', password: 'your_password'})
};
fetch('https://api.4casters.io/user/login', 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.4casters.io/user/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'username' => 'your_username',
'password' => 'your_password'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.4casters.io/user/login"
payload := strings.NewReader("{\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
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.4casters.io/user/login")
.header("Content-Type", "application/json")
.body("{\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.4casters.io/user/login")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"username\": \"your_username\",\n \"password\": \"your_password\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"user": {
"id": "<string>",
"username": "<string>",
"type": "free",
"oddsFormat": "american",
"displayBalance": 123,
"creditLimit": 123,
"liability": 123,
"commissionCharged": 123,
"maxLiability": 123,
"matchedVolume": {},
"openInterest": {},
"isAdmin": true,
"hasMarketMakerAccess": true,
"isPro": true,
"isDeposit": true,
"isAlphaUser": true,
"sportsbookDefault": true,
"defaultRotationNumbers": true,
"displayRotationNumbers": true,
"viewOddsWithCommission": true,
"defaultExpiry": 123,
"defaultOffer": 123,
"defaultSendOrderMessage": true,
"sportsbookMinimumDisplay": 123,
"showChatLastMessage": true,
"yesNoSummary": true,
"accessCode": "<string>",
"code": "<string>",
"p2pCode": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"emailConfirmation": true,
"auth": "<string>",
"email": "[email protected]",
"passwordSecurityChecks": {}
}
}
}{
"error": "<string>"
}**没有 API 密钥。**4casters 目前还不发放 API 密钥。使用你账户的用户名和密码登录,就像在网站上一样,然后使用返回的令牌。令牌如何在三套 API 中使用、以及如何处理它 30 天的有效期,见 认证概述。
登录
POST /user/login
curl -X POST https://api.4casters.io/user/login \
-H "Content-Type: application/json" \
-d '{"username": "your_username", "password": "your_password"}'
{
"username": "your_username",
"password": "your_password"
}
请求
string
必填
账户用户名(或邮箱)。
string
必填
账户密码。
响应
令牌会同时作为data.user.auth 以及签名 auth Cookie(Set-Cookie)返回。对于大多数服务端集成,你应捕获 data.user.auth 并丢弃 Cookie。
{
"data": {
"user": {
"id": "5fe37acbb5a23600123662c1",
"username": "your_username",
"auth": "5cd551d6...",
"type": "p2p",
"oddsFormat": "american",
"displayBalance": 1250.50,
"creditLimit": 500,
"liability": -125.00,
"commissionCharged": 0.01,
"hasMarketMakerAccess": false,
"isPro": false,
"createdAt": "2020-12-23T17:14:09.000Z"
}
}
}
User。
错误响应
| 状态 | 含义 |
|---|---|
400 | username 和 password 为必填。 |
401 | 用户名或密码不正确。 |
403 | 账户被封禁、锁定或已关闭。 |
429 | 超出登录速率限制。 |
为请求授权
在后续每个请求中传递来自data.user.auth 的令牌。按以下优先顺序接受三种请求头 / 载荷格式:
- Authorization 请求头(推荐)
- Cookie
- 请求体字段(仅 POST)
curl https://api.4casters.io/user/getMe \
-H "Authorization: Bearer 5cd551d6..."
Bearer 前缀是可选的 — 直接传递裸令牌也可以。/user/login 设置的签名 auth Cookie 在同一客户端复用时,会在每个端点上自动生效。{ "token": "5cd551d6...", "...": "..." }
401 InvalidCredentials。
令牌轮换
使用超过 30 天的令牌发起的已认证请求会自动轮换为新令牌。发生时,新令牌会在X-Auth-Token 响应头中返回(并作为更新后的签名 auth Cookie)。旧令牌立即失效;触发轮换的那次请求仍会成功,但之后任何使用旧值的请求都会返回 401。长期运行的集成应监听此响应头并持久化新值,或者干脆在遇到任何 401 时重新登录。
登出
POST /user/logout 会使发起该调用所用的令牌失效。之后使用该令牌的请求返回 401;同一账户持有的其他令牌不受影响。
双重认证
双重认证保护的是提现,而不是登录。无论账户的 2FA 设置如何,POST /user/login 都不会要求验证码。此页面对您有帮助吗?