Регистрация: Nov 2004
Адрес: Архангельская область
Сообщений: 492
|
Обычные Методы со стороны сервера и unknown method passed
Есть VKAP.class
PHP код:
<?php
/**
* Класс обертка, для VkApi. Здесь описываются методы для запросов.
*
* @package VkApi
* @author Michael Elovskih <wronglink@gmail.com>
*/
class VkApiNode
{
/**
* Конструктор класса. Принимает обязательные $api_id (Id приложения) и
* $secret (секретный код приложения).
*
* @param integer $api_id Id приложения.
* @param string $secret Секретный код приложения.
* @param string $format Формат ответа (XML или JSON). По умолчанию, 'XML'.
* @param string $version Версия API. По умолчанию, '2.0'.
* @param string $server_url Адрес сервера API. По умолчанию 'http://api.vkontakte.ru/api.php?'.
* @param mixed $timestamp Timestamp сервера. Если не задано - берется системное.
* @param mixed $random Случайное значение. Если не задано - задается через rand().
*/
public function __construct ($api_id,
$secret,
$format = 'XML',
$version = '2.0',
$server_url = 'http://api.vkontakte.ru/api.php?',
$timestamp = false,
$random = false)
{
$this->api_id = $api_id;
$this->method = '';
$this->secret = $secret;
$this->format = $format;
$this->version = $version;
$this->server_url = $server_url;
$this->timestamp = $timestamp ? $timestamp : time();
$this->random = $random ? $random : rand();
}
public function sendNotification ($uids, $message)
{
$api = new VkApi($this->api_id,
'secure.sendNotification',
$this->secret,
$this->format,
$this->version,
$this->server_url,
time(),
$this->random);
// $api->addParameter('uids', $uids);
$api->addParameter('uids', join(', ', $uids));
$api->addParameter('message', $message);
return $api->getQuery();
}
public function saveAppStatus ($uid, $status)
{
$api = new VkApi($this->api_id,
'secure.saveAppStatus',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
$api->addParameter('uid', $uid);
$api->addParameter('status', $status);
return $api->getQuery();
}
/**
* Возвращает платежный баланс приложения.
* @see http://vkontakte.ru/pages.php?o=-1&p=secure.getAppBalance
*
* @return string Строка запроса.
*/
public function getAppBalance ()
{
$api = new VkApi($this->api_id,
'secure.getAppBalance',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
return $api->getQuery();
}
public function getBalance ($uid)
{
$api = new VkApi($this->api_id,
'secure.getBalance',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
$api->addParameter('uid', $uid);
return $api->getQuery();
}
public function addVotes ($uid, $votes)
{
$api = new VkApi($this->api_id,
'secure.addVotes',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
$api->addParameter('uid', $uid);
$api->addParameter('votes', $votes);
return $api->getQuery();
}
public function withdrawVotes ($uid, $votes)
{
$api = new VkApi($this->api_id,
'secure.withdrawVotes',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
$api->addParameter('uid', $uid);
$api->addParameter('votes', $votes);
return $api->getQuery();
}
public function transferVotes ($uid_from, $uid_to, $votes)
{
$api = new VkApi($this->api_id,
'secure.transferVotes',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
$api->addParameter('uid_from', $uid_from);
$api->addParameter('uid_to', $uid_to);
$api->addParameter('votes', $votes);
return $api->getQuery();
}
public function getTransactionsHistory ($type = 0, $uid_from = null, $uid_to = null, $date_from = null, $date_to = null, $limit = 1000)
{
$api = new VkApi($this->api_id,
'secure.getTransactionsHistory',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
if($type)
$api->addParameter('type', $type);
if($uid_from)
$api->addParameter('uid_from', $uid_from);
if($uid_to)
$api->addParameter('uid_to', $uid_to);
if($date_from)
$api->addParameter('date_from', $date_from);
if($date_to)
$api->addParameter('date_to', $date_to);
if($limit)
$api->addParameter('limit', $limit);
return $api->getQuery();
}
public function GetAudioServer ()
{
$api = new VkApi($this->api_id,
'getAudioUploadServer',
$this->secret,
$this->format,
$this->version,
$this->server_url,
$this->timestamp,
$this->random);
return $api->getQuery();
}
}
class VkApi
{
public function __construct ($api_id,
$method,
$secret,
$format,
$version,
$server_url,
$timestamp,
$random)
{
$this->api_id = $api_id;
$this->method = $method;
$this->secret = $secret;
$this->format = $format;
$this->version = $version;
$this->server_url = $server_url;
$this->timestamp = $timestamp;
$this->random = $random;
$this->parameters = array();
$this->parameters[] = array('name' => 'api_id', 'value' => $this->api_id);
$this->parameters[] = array('name' => 'method', 'value' => $this->method);
$this->parameters[] = array('name' => 'format', 'value' => $this->format);
$this->parameters[] = array('name' => 'v', 'value' => $this->version);
$this->parameters[] = array('name' => 'timestamp','value' => $this->timestamp);
$this->parameters[] = array('name' => 'random', 'value' => $this->random);
}
public function __toString ()
{
$this->parameters[] = array('name' => 'sig', 'value' => $this->getSig());
foreach($this->parameters as $p)
$query[] = $p['name'].'='.rawurlencode($p['value']);
return $this->server_url . join('&', $query);
}
public function addParameter ($p_name, $p_value)
{
$this->parameters[] = array('name' => $p_name, 'value' => $p_value);
}
public function getQuery ()
{
return $this->__toString();
}
private function getSig ()
{
sort($this->parameters);
$sigStr = '';
foreach($this->parameters as $p)
$sigStr .= join('=',$p);
return md5($sigStr . $this->secret);
}
}
?>
Пытаюсь получить адрес для загрузки mp3
пишет unknown method passed
PHP код:
require('VkApi.class.php');
$api = new VkApiNode('1707664', 'eD44qE5Dge3fa21M2de');
$server = $api->GetAudioServer();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xmlstr = curl_exec($ch);
curl_close($ch);
print_r($xmlstr);
Не понятно почему
Код:
<?xml version="1.0" encoding="utf-8"?>
<error>
<error_code>3</error_code>
<error_msg>Unknown method passed</error_msg>
<request_params list="true">
<param>
<key>api_id</key>
<value>1707664</value>
</param>
<param>
<key>format</key>
<value>XML</value>
</param>
<param>
<key>method</key>
<value>getAudioUploadServer</value>
</param>
<param>
<key>random</key>
<value>1709254990</value>
</param>
<param>
<key>timestamp</key>
<value>1315488561</value>
</param>
<param>
<key>v</key>
<value>2.0</value>
</param>
<param>
<key>sig</key>
<value>ab025261d4fb3dd4dfef6334547b5d8e</value>
</param>
</request_params>
</error>
__________________
-------------------------------
FLASH FLASH FLASH FLASH FLASH
|