IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Développement Web avec .NET Discussion :

Soucis pour convertir un code PHP en C# pour accéder à une Web API


Sujet :

Développement Web avec .NET

  1. #1
    Membre actif
    Inscrit en
    Février 2006
    Messages
    311
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 311
    Points : 253
    Points
    253
    Par défaut Soucis pour convertir un code PHP en C# pour accéder à une Web API
    Bonsoir ,

    J'essaie de convertir ce code PHP pour se connecter à une api en C# mais j'éprouve du mal pour
    trouver les fonctions équivalentes ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    <?php
    /**
    ©CEDEMO - 1998-2014
    Example of Cedemo Rest API CALL in PHP
    */
     
    #Auth Mode
    #how the client_id / client_secret should be transmitted to the API
    $authMode = "header"; #header / post
    #Client ID
    $clientID = '';
    #Client Secret
    $clientSecret = '';
     
    #END OF CONFIGURATION PART
     
    if(empty($clientID) || empty($clientSecret)){
    	echo "ClientID / ClientSecret must be set in the file";
    	exit;
    }
     
    #Retrieve the access Token
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.cedemo.com/get_token");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    #Auth parameter in header
    if ($authMode == "header") {
        curl_setopt($ch, CURLOPT_USERPWD, $clientID . ':' . $clientSecret);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('grant_type' => 'client_credentials'));
    } #Auth parameter in post variables
    elseif ($authMode == "post") {
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('grant_type' => 'client_credentials', 'client_id' => $clientID, 'client_secret' => $clientSecret));
    }
    $response = curl_exec($ch);
    $resultStatus = curl_getinfo($ch);
    curl_close($ch);
    if ($resultStatus['http_code'] == 200) {
        $dom = new DOMDocument;
        $dom->loadXML($response);
        if (!$dom) {
            echo 'Error while parsing the document';
            exit;
        }
        $simpleXML = simplexml_import_dom($dom);
     
    #display the xml object
        echo "<pre>";
        print_r($simpleXML);
        echo "</pre>";
     
    #display the access token
        $accessToken = (string)$simpleXML->access_token[0];
        echo "<pre>";
        var_export($accessToken);
        echo "</pre>";
     
    #Perform metadata videogame search request
        $aParams = array('title' => 'Fifa 14', 'access_token' => $accessToken);
        $queryParams = http_build_query($aParams);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.cedemo.com/metadata/videogame/search?" . $queryParams);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_POST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        $resultStatus = curl_getinfo($ch);
        curl_close($ch);
        if ($resultStatus['http_code'] == 200) {
            $dom = new DOMDocument;
            $dom->loadXML($response);
            if (!$dom) {
                echo 'Error while parsing the document';
                exit;
            }
            $simpleXML = simplexml_import_dom($dom);
            #display the xml object
            echo "<pre>";
            print_r($simpleXML);
            echo "</pre>";
     
            if (isset($simpleXML->MetaDataRef[0])) {
     
                if (isset($simpleXML->MetaDataRef[0]->attributes()->CedemoMetaDataId)) {
                    $code = (string)$simpleXML->MetaDataRef[0]->attributes()->CedemoMetaDataId;
                    $codeType = 'CedemoMetaDataId';
                } elseif (isset($simpleXML->MetaDataRef[0]->attributes()->EAN)) {
                    $code = (string)$simpleXML->MetaDataRef[0]->attributes()->EAN;
                    $codeType = 'EAN';
                } elseif (isset($simpleXML->MetaDataRef[0]->attributes()->UPC)) {
                    $code = (string)$simpleXML->MetaDataRef[0]->attributes()->UPC;
                    $codeType = 'UPC';
                } else {
                    echo "No code / code  type found";
                    exit;
                }
     
                #Perform metadata videogame get request
                $aParams = array('code' => $code, 'code_type' => $codeType, 'access_token' => $accessToken);
                $queryParams = http_build_query($aParams);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "https://api.cedemo.com/metadata/videogame/get?" . $queryParams);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_POST, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $response = curl_exec($ch);
                $resultStatus = curl_getinfo($ch);
                curl_close($ch);
                if ($resultStatus['http_code'] == 200) {
                   $dom = new DOMDocument;
            $dom->loadXML($response);
            if (!$dom) {
                echo 'Error while parsing the document';
                exit;
            }
            $simpleXML = simplexml_import_dom($dom);
            #display the xml object
            echo "<pre>";
            print_r($simpleXML);
            echo "</pre>";
                }
            } else {
                echo "Error  during the request";
                echo "<pre>";
                print_r($response);
                echo "</pre>";
     
            }
     
        } else {
            echo "Error  during the request";
            echo "<pre>";
            print_r($response);
            echo "</pre>";
     
        }
     
     
    } else {
        echo "Error  during the request";
        echo "<pre>";
        print_r($response);
        echo "</pre>";
     
    }

    Si un expert en C# pourrait m'aider à le convertir le PHP ?
    Merci d'avance.

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2013
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2013
    Messages : 27
    Points : 7
    Points
    7
    Par défaut J'essaie de mettre à jour ce code avec les requêtes PDO mais j'éprouve du mal pour trouver les fonctions équi
    Citation Envoyé par Johnny P. Voir le message
    Bonsoir ,

    J'essaie de mettre à jour ce code avec les requêtes PDO mais j'éprouve du mal pour
    trouver les fonctions équivalentes ?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    <?php
    /**
    ©CEDEMO - 1998-2014
    Example of Cedemo Rest API CALL in PHP
    */
     
    #Auth Mode
    #how the client_id / client_secret should be transmitted to the API
    $authMode = "header"; #header / post
    #Client ID
    $clientID = '';
    #Client Secret
    $clientSecret = '';
     
    #END OF CONFIGURATION PART
     
    if(empty($clientID) || empty($clientSecret)){
    	echo "ClientID / ClientSecret must be set in the file";
    	exit;
    }
     
    #Retrieve the access Token
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.cedemo.com/get_token");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    #Auth parameter in header
    if ($authMode == "header") {
        curl_setopt($ch, CURLOPT_USERPWD, $clientID . ':' . $clientSecret);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('grant_type' => 'client_credentials'));
    } #Auth parameter in post variables
    elseif ($authMode == "post") {
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('grant_type' => 'client_credentials', 'client_id' => $clientID, 'client_secret' => $clientSecret));
    }
    $response = curl_exec($ch);
    $resultStatus = curl_getinfo($ch);
    curl_close($ch);
    if ($resultStatus['http_code'] == 200) {
        $dom = new DOMDocument;
        $dom->loadXML($response);
        if (!$dom) {
            echo 'Error while parsing the document';
            exit;
        }
        $simpleXML = simplexml_import_dom($dom);
     
    #display the xml object
        echo "<pre>";
        print_r($simpleXML);
        echo "</pre>";
     
    #display the access token
        $accessToken = (string)$simpleXML->access_token[0];
        echo "<pre>";
        var_export($accessToken);
        echo "</pre>";
     
    #Perform metadata videogame search request
        $aParams = array('title' => 'Fifa 14', 'access_token' => $accessToken);
        $queryParams = http_build_query($aParams);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.cedemo.com/metadata/videogame/search?" . $queryParams);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_POST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        $resultStatus = curl_getinfo($ch);
        curl_close($ch);
        if ($resultStatus['http_code'] == 200) {
            $dom = new DOMDocument;
            $dom->loadXML($response);
            if (!$dom) {
                echo 'Error while parsing the document';
                exit;
            }
            $simpleXML = simplexml_import_dom($dom);
            #display the xml object
            echo "<pre>";
            print_r($simpleXML);
            echo "</pre>";
     
            if (isset($simpleXML->MetaDataRef[0])) {
     
                if (isset($simpleXML->MetaDataRef[0]->attributes()->CedemoMetaDataId)) {
                    $code = (string)$simpleXML->MetaDataRef[0]->attributes()->CedemoMetaDataId;
                    $codeType = 'CedemoMetaDataId';
                } elseif (isset($simpleXML->MetaDataRef[0]->attributes()->EAN)) {
                    $code = (string)$simpleXML->MetaDataRef[0]->attributes()->EAN;
                    $codeType = 'EAN';
                } elseif (isset($simpleXML->MetaDataRef[0]->attributes()->UPC)) {
                    $code = (string)$simpleXML->MetaDataRef[0]->attributes()->UPC;
                    $codeType = 'UPC';
                } else {
                    echo "No code / code  type found";
                    exit;
                }
     
                #Perform metadata videogame get request
                $aParams = array('code' => $code, 'code_type' => $codeType, 'access_token' => $accessToken);
                $queryParams = http_build_query($aParams);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "https://api.cedemo.com/metadata/videogame/get?" . $queryParams);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_POST, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $response = curl_exec($ch);
                $resultStatus = curl_getinfo($ch);
                curl_close($ch);
                if ($resultStatus['http_code'] == 200) {
                   $dom = new DOMDocument;
            $dom->loadXML($response);
            if (!$dom) {
                echo 'Error while parsing the document';
                exit;
            }
            $simpleXML = simplexml_import_dom($dom);
            #display the xml object
            echo "<pre>";
            print_r($simpleXML);
            echo "</pre>";
                }
            } else {
                echo "Error  during the request";
                echo "<pre>";
                print_r($response);
                echo "</pre>";
     
            }
     
        } else {
            echo "Error  during the request";
            echo "<pre>";
            print_r($response);
            echo "</pre>";
     
        }
     
     
    } else {
        echo "Error  during the request";
        echo "<pre>";
        print_r($response);
        echo "</pre>";
     
    }

    Si un expert en C# pourrait m'aider à le convertir le PHP ?
    Merci d'avance.

Discussions similaires

  1. Convertir les codes HTML en équivalent pour JavaScript
    Par bubulemaster dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 20/08/2009, 11h20
  2. quel logiciel pour convertir le code en flow chart ?
    Par schneiderj dans le forum Autres éditeurs
    Réponses: 7
    Dernier message: 02/02/2009, 11h26
  3. comment faire pour que le code PHP dialogue avec mes bibliotheques compilées
    Par Samson BAYIHA dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 22/09/2007, 01h45
  4. Réponses: 11
    Dernier message: 19/02/2007, 00h20
  5. Réponses: 2
    Dernier message: 07/07/2006, 21h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo