问题描述
几天来我一直在尝试建立有效的API连接。但这不起作用。
不适用于我的地方:“身体”部分。 我可以看到所有内容,但无法过滤任何内容,
商店系统是:商店软件: API的说明如下: https://docs.shopware.com/en/shopware-platform-dev-en/admin-api-guide/reading-entities?category=shopware-platform-dev-en/admin-api-guide
Shopware专注于难题: http://docs.guzzlephp.org/en/stable/index.html
不适用于我的地方:“身体”部分。 我可以看到所有内容,但无法过滤任何内容,
['body'=> $ inhalt]
示例:https://www.plintenburg.com/client.php
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require_once '../vendor/autoload.php';
use GuzzleHttp\Client;
$client = new GuzzleHttp\Client([
'base_uri' => 'https://www.plintenburg.com','timeout' => 2.0,'headers' => ['Content-Type' => 'application/json'],'verify' => false,]);
$clientId = "SWIAEHBRZWRUBTDBCNJ2SVLNTW";
$clientSecret = "dzFNMEZXWUxpZFBucnRaS0g5cHJRSVFvNVUxNkZzc2YzR0pPNHM";
$body1 = json_encode([
'client_id' => $clientId,'client_secret' => $clientSecret,'grant_type' => 'client_credentials','scopes' => 'write',]);
$response = $client->post(
'/api/oauth/token',[
'Content-Type' => 'application/json','body' => $body1
]
);
$token = json_decode($response->getBody()->getContents(),true);
//Das ist die TokenAcces ausgebe!!
//print_r($token);
//my first attempt at using the body variable. Without success
$body ='{
"ids": [
"11dc680240b04f469ccba354cbf0b967","1901dc5e888f4b1ea4168c2c5f005540","1f54875c658f464f95c198b9137391c4"
],"includes": {
"product": ["id","name"]
}
}';
//my second attempt at using the body variable. Without success
$inhalt ='{
"filter": [
{ "type": "equals","field": "productNumber","value": "SWDEMO10002" }
],"name","productNumber"]
}
}';
//my third attempt to use the body variable. Without success
$body3 = json_encode([
'includes' => [
'product' => ['id','name'],],]);
echo $inhalt;
$token = json_decode((string) $response->getBody(),true)['access_token'];
// mit access_token endpunkt auslesen
if (isset($token)) {
$response = $client->request('POST','/api/v3/search/product',[
'headers' => [
'User-agent'=> 'Mozilla/5.0','Authorization' => 'Bearer ' . $token,'Content-Type' => 'application/json','Content-Length' => '0','Accept'=> '*/*','Accept-Encoding'=> 'gzip',['body' => $inhalt]
);
//echo $response->getBody();
// Ausgabe
//return $response;
$body = $response->getBody();
$json_string = json_decode($body,JSON_PRETTY_PRINT);
header('Content-Type: application/json');
print_r($json_string);
} else {
return response()->json(['error' => request('error')]);
}
?>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)