私は認証を機能させており、クエリの戻り値が欠落しているように見える理由で、postmanでクエリをテストしました。
function generate_edge_curl(){
$endpoint = $this->get_endpoint();
$auth_token = $this->token->get_token();
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'x-amz-user-agent: aws-amplify/2.0.1',
'content-type: application/json',
'Authorization: '.$auth_token['access_token'],
));
return $ch;
}
function get_bidders(){
$ch = $this->generate_edge_curl();
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"query":"{
auctionInfo(id: \'alldal\') {
bidders {
list {
companyAmsId
companyName
firstName
lastName
badgeNum
bidderType
}
}
}
}"}');
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);
}
戻り値
string(133) "{
"errors" : [ {
"message" : "Invalid JSON payload in POST request.",
"errorType" : "MalformedHttpRequestException"
} ]
}"
私はグラフqlを初めて使用しますが、ここで何が欠けていますか?
だから、いくつかの掘り下げと多くの失敗した試みの後、これは私が思いついたものです。
function generate_edge_curl(){
$endpoint = $this->get_endpoint();
$auth_token = $this->token->get_token();
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'x-amz-user-agent: aws-amplify/2.0.1',
'content-type: application/json',
'Authorization: '.$auth_token['access_token'],
));
return $ch;
}
function get_bidders(){
$query = <<<'GRAPHQL'
query {
auctionInfo(id: "alldal") {
bidders {
list {
companyAmsId
companyName
firstName
lastName
badgeNum
bidderType
}
}
}
}
GRAPHQL;
$ch = $this->generate_edge_curl();
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['query' => $query]));
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);
}
主な変更点は、クエリを次のように保存することでした。
$query = <<<'GRAPHQL'
query {
auctionInfo(id: "alldal") {
bidders {
list {
companyAmsId
companyName
firstName
lastName
badgeNum
bidderType
}
}
}
}
GRAPHQL;
次に、その文字列をjson_encodingします。 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['query' => $query]))
私はここからアイデアを得ましたhttps://gist.github.com/dunglas/05d901cb7560d2667d999875322e690a
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加