最近在做一个类似 stmbuy 的应用,开发过程需要对接 steam api 获取用户的公开库存,在查阅 steam api 文档 后发现可以使用 https://partner.steam-api.com/IInventoryService/GetInventory/v1 接口获取,但是我调用一直是报 403 错误。

我的代码如下:

namespace App\Http\Controllers\Api; use App\Http\Requests\Api\OrnamentRequest; use App\Models\Ornament; use App\Transformers\OrnamentTransformer; use GuzzleHttp\Client; use Illuminate\Http\Request; class OrnamentsController extends Controller public function inventory(){ $client_http=new Client(['verfiy'=>false]); $url="https://partner.steam-api.com/IInventoryService/GetInventory/v1/?key=key"; $input_json=json_encode([ "appid"=>570, "steamid"=>"steamid", $input_json_url_encode=urlencode($input_json); $url=$url."&input_json=".$input_json_url_encode; $response= $client_http->request("get",$url); }catch (\Exception $exception){ return ['status' => 500, 'msg' => $exception->getMessage(), 'info' => []]; $status = $response->getStatusCode(); $json_content = $response->getBody()->getContents(); if ($status!=200){ return ['status' => $status, 'msg' => '', 'info' => []]; return ["url"=>$url,"response"=>$json_content];

steam api 接口区分普通接口和服务(service)接口,除了传参数方式不一样外,服务接口还要使用开发者 web api 密钥,在调用服务接口的使用我已经使用了开发者密钥。

我试过普通的接口,很轻松的获取到结果了,比如: https://api.steampowered.com/ISteamUser/GetFriendList/v1/

感谢您看我的问题,我尝试了在网上搜索解决,但是失败了,如果您知道怎么解决,麻烦告诉我我该怎么做?如果您需要报酬才能解决的话,可以私信我报个价。

steam