Un computer registra se: il SDK corre là, scambia la chiave, e la macchina devenia un storage. Un telefono non può — il SDK non è nel e non deve ser, perché la chiave sarebbe. Quindi la pagina envia un identificator al servèrver, e il servèrvèr l'aclama.
Parâmetros
deviceIdstringobrigatórioUn identificator al azar la pagina mantiene. Manca → il SDK lança.
namestringIl nome display. Derivè del agente utente quando ausente.
userAgentstringAgent d'usuari del telefono, usat per quel nome.
Il medès divizimentId è il medès stoccatè
L'invocare di nuovo con un identificatore già visto restitue il stoccaggio existente in lugar de fare un altro. Così la pagina puèt inchinar a ogni carica senza cumulare registrazioni — e due chiamate simultanee ancora producen uno.
// In the page: an identifier that survives reloads
let deviceId = localStorage.getItem("device");
if (!deviceId) {
deviceId = `dev_${crypto.randomUUID()}`;
localStorage.setItem("device", deviceId);
}
// On your server, where the key is
export async function registerPhone(deviceId, userAgent) {
const phone = await api.storage.device({ deviceId, userAgent });
return phone.id;
}# In the page (JavaScript): an identifier that survives reloads
# localStorage.getItem("device") || `dev_${crypto.randomUUID()}`
# On your Python server, where the key is
def register_phone(device_id, user_agent):
phone = api.storage.device(device_id=device_id, user_agent=user_agent)
return phone.idUn valore costruito a partir del agente utente, l'ecran o un cont è lo stesso per molte persone — e chi lo envia ottiene que storage. Random, mantenut in browser, è lo che lo rende un dispositivo.
Retorno
phone.id;
phone.type; // "phone"
phone.provider; // "browser"
phone.deviceId; // the identifier you passedphone.id
phone.type # "phone"
phone.provider # "browser"I suoi files non sono a conta
Salvar a lui a través del server è negat con storage_is_local. Lectura e scrivi-le avviene in la pagina, che è onde sono — il server releve la richiesta e la pagina risponde.
E questo rende un telefono un luogo sensat per un agente per lavorare: nulla è caricat per lettura. i pods de limas.
appName separa due apps su un telefono
Un storage è identificat dal conto, il dispositivo e il appName il client è stato costruito con. Due apps in un telefono sono due storages — che è generalmente quello che si desidera, dal momento que i loro files non hanno nulla a che fare l'un cun l'altro.
const api = new IaGenify({ apiKey, appName: "field-notes" });
await api.storage.device({ deviceId }); // this app's storage on this phoneapi = IaGenify(api_key=api_key, app_name="field-notes")
api.storage.device(device_id=device_id) # this app's storage on this phoneErros
| Código | Status | Quando |
|---|---|---|
| — (erro lançado localmente) | — | Nessun dispositivo ha superat. |
| non autorizzato | 401 | Non sessione o chiave valida — la chiamata è del tuo server, non del telefono. |