Connectez-vous à l'API Dutchie à l'aide de requêtes PHP GraphQL
P粉549986089
P粉549986089 2024-03-27 18:56:18
0
1
373

J'ai une boutique sur Dutchie.com. Je souhaite utiliser une clé API pour accéder à leurs produits. Cela doit être fait via l'API Dutchie utilisant GraphQL intégré à PHP.

Voici un exemple de clé API :

public-eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJBUEktQ0xJRU5UIiwiZXhwIjozMzE4NjM5Mjc0NSwiaWF0IjoxNjI5NDgzOTQ1LCJpc3MiOiJodHRwczovL2R1dGNoY29tIiwianRpIjoiNGMtOTMyOC00MjhkLWEyYTMtOWQzMTc2ZTUwODY0IiwiZW50ZXJwcmlzZV9pZChLWExYTctNDM3OC05NWY4LTNlYzVzBiNSIsInV1aWQiOiI0M2ZlMjdkNy1iZWU2LTQxOTgtYWNhMi03N2Y5Y2I3MjI5MGIifQ.hCQWpcQ5uhKnZOSVQDA5SCMkx5kopC7H3upeU-1jMpg

Il s'agit d'une mutation GraphQL Ping.

mutation Ping {
  ping {
    id,
    time
  }
}

Point final Dutchie : https://plus.dutchie.com/plus/2021-07/graphql

paramètres d'en-tête http { "Autorisation": "Hébergez la clé API ici" }

Sortie Ping

En gros, je souhaite exécuter une requête GraphQL dans ma page PHP. Je l'ajouterai à ma page WordPress plus tard.

J'ai essayé la bibliothèque php php-graphql-client. Quelqu'un peut-il m'aider à le faire en utilisant la bibliothèque ci-dessus ou une autre serait vraiment reconnaissante. J'ai perdu trop de temps là-dessus car je connais très peu de choses sur GraphQL.

C'est le code que j'ai essayé.

$client = new Client(
    'https://plus.dutchie.com/plus/2021-07/graphql',
    ['Authorization => Bearer API Key here']
);
 

 
// Create the GraphQL mutation
$gql = (new Mutation('Ping'))
    ->setSelectionSet(
        [
            'id',
            'time',
        ]
    );

// Run query to get results
try {
    $results = $client->runQuery($gql);
}
catch (QueryError $exception) {

    // Catch query error and desplay error details
    print_r($exception->getErrorDetails());
    exit;
}

// Display original response from endpoint
var_dump($results->getResponseObject());

// Display part of the returned results of the object
var_dump($results->getData()->pokemon);

// Reformat the results to an array and get the results of part of the array
$results->reformatResults(true);
print_r($results->getData()['data']);

L'erreur que j'ai eue. https://github.com/guzzle/psr7/blob/master/src/MessageTrait.php

P粉549986089
P粉549986089

répondre à tous(1)
P粉648469285

au lieu de :

$client = new Client(
    'https://plus.dutchie.com/plus/2021-07/graphql',
    ['Authorization => Bearer API Key here']
);

Essayez

$client = new Client(
    'https://plus.dutchie.com/plus/2021-07/graphql',
    ['Authorization' => 'Bearer API Key here']
);
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!