我正在尝试使用Magickartenmarkt RESTful API验证我的帐户。
以下是上述API的链接。 https://www.mkmapi.eu/ws/documentation/API_2.0:Main_Page
我的代码如下:
<?php
$method = "GET";
$url = "https://www.mkmapi.eu/ws/v2.0/account";
$appToken = "My App token"; //double checked in my account
$appSecret = "My App secret"; //double checked in my account
$accessToken = "My Access token"; //double checked in my account
$accessSecret = "My Access token secret"; //double checked in my account
$nonce = uniqid();
$timestamp = time();
$signatureMethod = "HMAC-SHA1";
$version = "2.0";
/**
* Gather all parameters that need to be included in the Authorization header and are know yet
*
* @var $params array|string[] Associative array of all needed authorization header parameters
*/
$params = array(
'realm' => $url,
'oauth_consumer_key' => $appToken,
'oauth_token' => $accessToken,
'oauth_nonce' => $nonce,
'oauth_timestamp' => $timestamp,
'oauth_signature_method' => $signatureMethod,
'oauth_version' => $version,
);
/**
* Start composing the base string from the method and request URI
*
* @var $baseString string Finally the encoded base string for that request, that needs to be signed
*/
$baseString = strtoupper($method) . "&";
$baseString .= rawurlencode($url) . "&";
/*
* Gather, encode, and sort the base string parameters
*/
$encodedParams = array();
foreach ($params as $key => $value)
{
if ("realm" != $key)
{
$encodedParams[rawurlencode($key)] = rawurlencode($value);
}
}
ksort($encodedParams);
/*
* Expand the base string by the encoded parameter=value pairs
*/
$values = array();
foreach ($encodedParams as $key => $value)
{
$values[] = $key . "=" . $value;
}
$paramsString = rawurlencode(implode("&", $values));
$baseString .= $paramsString;
/*
* Create the signingKey
*/
$signatureKey = rawurlencode($appSecret) . "&" . rawurlencode($accessSecret);
/**
* Create the OAuth signature
* Attention: Make sure to provide the binary data to the Base64 encoder
*
* @var $oAuthSignature string OAuth signature value
*/
$rawSignature = hash_hmac("sha1", $baseString, $signatureKey, true);
$oAuthSignature = base64_encode($rawSignature);
/*
* Include the OAuth signature parameter in the header parameters array
*/
$params['oauth_signature'] = $oAuthSignature;
/*
* Construct the header string
*/
$header = "Authorization: OAuth ";
$headerParams = array();
foreach ($params as $key => $value)
{
$headerParams[] = $key . "=\"" . $value . "\"";
}
$header .= implode(", ", $headerParams);
/*Initialisation de la ressource curl*/
$curlHandle = curl_init();
/*
* Set the required cURL options to successfully fire a request to MKM's API
*
* For more information about cURL options refer to PHP's cURL manual:
* http://php.net/manual/en/function.curl-setopt.php
*/
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array($header));
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
/**
* Execute the request, retrieve information about the request and response, and close the connection
*
* @var $content string Response to the request
* @var $info array Array with information about the last request on the $curlHandle
*/
$content = curl_exec($curlHandle);
$info = curl_getinfo($curlHandle);
curl_close($curlHandle);
/*
* Convert the response string into an object
*
* If you have chosen XML as response format (which is standard) use simplexml_load_string
* If you have chosen JSON as response format use json_decode
*
* @var $decoded \SimpleXMLElement|\stdClass Converted Object (XML|JSON)
*/
// $decoded = json_decode($content);
$decoded = simplexml_load_string($content);
var_dump($content);
?>
var_dump返回
找不到资源。错误路由器不匹配
此代码可在此处找到:https://www.mkmapi.eu/ws/documentation/API:Auth_libcurl
我试图获取谷歌网页,它工作正常,所以我不认为这是cURL问题。
我不确定此API是否有效。需要一些帮助以确保这一点。是API还是我的代码?
答案 0 :(得分:0)
关于https://www.mkmapi.eu/ws/documentation/API_Main_Page的信息表明Api 2.0还没有上线。只有它的文档是。