You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mobile.de Seller API认证失败求助:调用返回401 Unauthorized

Mobile.de Seller API 401 认证失败问题

问题描述

使用Mobile.de Seller API时遭遇认证失败,调用接口后返回401 Unauthorized状态码。已按照要求采用Basic Auth方式传入用户名和密码,但仍然无法通过认证。此前仅使用过Directus RestAPI。

调用代码

let url = 'https://services.mobile.de/seller-api/sellers/sellerid/ads';
let username = 'username';
let password = 'password';

let headers = new Headers();
headers.set('Authorization', 'Basic ' + base64.encode(username + ":" + password));
fetch(url, {method:'GET',
  headers: headers,
})
    .then(response => console.log(response))

控制台返回信息

Response {
  size: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    stream: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    boundary: null,
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    type: 'default',
    url: 'https://services.mobile.de/seller-api/sellers/mobileID/ads',
    status: 401,
    statusText: 'Unauthorized',
    headers: {
      connection: 'close',
      'content-length': '0',
      date: 'Thu, 06 Oct 2022 23:52:28 GMT',
      'www-authenticate': 'Basic realm="mobile.de api"'
    },
    counter: 0,
    highWaterMark: 16384
  }
}
Response {
  size: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    stream: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    boundary: null,
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    type: 'default',
    url: 'https://services.mobile.de/seller-api/sellers/mobileid/ads',
    status: 401,
    statusText: 'Unauthorized',
    headers: {
      connection: 'close',
      'content-length': '0',
      date: 'Thu, 06 Oct 2022 23:52:28 GMT',
      'www-authenticate': 'Basic realm="mobile.de api"'
    },
    counter: 0,
    highWaterMark: 16384
  }
}

解决方案
  1. 替换Base64编码方法
    浏览器环境下不要用自定义的base64.encode,直接使用原生btoa()方法,第三方库可能存在编码规则差异(比如特殊字符、换行符处理)。修改后的请求头代码:
headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));
  1. 验证凭据有效性
    确认使用的是Mobile.de Seller API专属认证凭据,而非普通网站登录账号——部分平台会为API单独生成独立密钥,与前台账号不通用。

  2. 修正Seller ID大小写
    从返回的请求URL可见,你实际请求的mobileID和mobileid大小写不一致,API对路径参数通常大小写敏感,需确认Seller ID拼写完全匹配官方提供的内容。

  3. 检查请求头格式
    确保Authorization头格式完全正确:Basic 后紧跟Base64字符串,无多余空格,用户名与密码间的冒号为英文半角。

  4. 用工具快速验证
    用curl直接测试凭据有效性,排除代码层面问题:

curl -u "username:password" https://services.mobile.de/seller-api/sellers/[你的SellerID]/ads

若curl也返回401,说明凭据本身存在问题,需联系Mobile.de支持团队确认权限或重置凭据。


内容的提问来源于stack exchange,提问作者iBeiros

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 00:25:18