記事を検索しましたが、xmlrpcでサービスのユーザーポイントを使用する方法がまだわかりません。(My Environment drupal 7、Service 3.x、userpoints)
userpointsモジュールのreadmeを読みました。
$result = xmlrpc($server_url, 'userpoints.points', $key, $uid, $points, $tid, $event, $description);
私は他のサイトでこのコードを書いて、ポイントを加算/減算しようとしましたが、動作しません。
drupal APIで関数xmlrpc()を試し、APIルールに従いましたが、どちらも機能しません。drupal api関数:xmlrpc($ url、$ args、$ options = array())
私が書いたコード:
$key='1234';// casually set
$uid=1;
$points=1;
$tid=18;
$event='event testing';
$description='description testing';
$result = xmlrpc('http://my.domain/userpoints-api/', array(
'userpoints.points' => array($key, $uid,$points,$tid,$event,$description),
));
dpm($result);
$ resultは何もありません。誰かこれについての経験がありますか?君たちありがとう。私を助けてください。
私はaccess.logを確認しました私は以下のメッセージを得ました
210.65.11.209 - - [23/Aug/2013:15:49:50 +0800] "POST /userpoints-api/add HTTP/1.0" 200 767 "-" "Drupal (+drupal.org/)
私はxmlrpc($ server_url、 'userpoints.points'、$ key、$ uid、$ points、$ tid、$ event、$ description)が動作するかどうかをテストしませんでした。
代わりに、私は [〜#〜] postman [〜#〜] 拡張を使用してchromeストアからデータをuserpointsサービスAPIエンドポイントパスに投稿します。
<?xml version="1.0"?> <methodCall> <methodName>pointss.add</methodName> <params> <param> <name>uid</name> <value><int>1</int></value> <name>points</name> <value><int>170</int></value> <name>tid</name> <value><int>18</int></value> <name>operation</name> <value><string>test for operation</string></value> <name>description</name> <value><string>test for description</string></value> <name>entity_type</name> <value><string>node</string></value> <name>entity_id</name> <value><int>1</int></value> </param> </params> </methodCall>
できました。
Userpoints ServicesはRestサーバーとXmlRPCサーバーをサポートします
userpoints_serviceのコードを変更しました
ユーザーポイントでRest Serverを使用できるようになりました
/**
* Implementation of hook_services_resources().
*/
function userpoints_service_services_resources() {
return array(
'userpoints' => array(
'retrieve' => array(
'help' => 'Retrieve the amount of points a user has',
'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
'callback' => 'userpoints_service_get',
'access callback' => 'userpoints_service_view_access',
'access arguments append' => TRUE,
'args' => array(
array(
'name' => 'uid',
'type' => 'int',
'optional' => FALSE,
'description' => 'The User ID for which the points should be loaded. Defaults to the .',
'source' => array('path' => 0),
),
array(
'name' => 'tid',
'type' => 'all',
'optional' => TRUE,
'source' => array('path' => 1),
'description' => t('An optional Term ID for the category.'),
),
array(
'name' => 'type',
'type' => 'string',
'optional' => TRUE,
'source' => array('path' => 2),
'description' => t('The type of points, either max or current, to which it defaults.'),
),
),
),
'update'=>array(
'help' => 'Add or subtract a given amount of points for a user',
'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
'callback' => 'userpoints_service_add',
'access callback' => 'userpoints_admin_access',
'access arguments' => array('add'),
'args' => array(
array(
'name' => 'uid',
'type' => 'int',
'optional' => FALSE,
'description' => 'A valid Drupal User ID.',
'source' => array('path' => 0),
),
array(
'name' => 'points',
'type' => 'int',
'optional' => FALSE,
'source' => array('param' => 'points'),
'description' => 'Number of points to add/subtract.',
),
array(
'name' => 'tid',
'type' => 'int',
'optional' => TRUE,
'source' => array('data' => 'tid'),
'description' => t('An optional Term ID for the category.'),
),
array(
'name' => 'operation',
'type' => 'string',
'optional' => TRUE,
'source' => array('data' => 'operation'),
'description' => t('An operation string for this transaction.'),
),
array(
'name' => 'description',
'type' => 'string',
'optional' => TRUE,
'source' => array('data' => 'description'),
'description' => t('An optional description of this transaction.'),
),
array(
'name' => 'entity_type',
'type' => 'string',
'optional' => TRUE,
'source' => array('data' => 'entity_type'),
'description' => t('An optional description of this transaction.'),
),
array(
'name' => 'entity_id',
'type' => 'int',
'optional' => TRUE,
'source' => array('data' => 'entity_id'),
'description' => t('An optional description of this transaction.'),
),
),
),
'index' => array(
'help' => 'Index of all users with points',
'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
'callback' => 'userpoints_service_index',
'access callback' => 'userpoints_service_view_access',
'args' => array(
array(
'name' => 'page',
'optional' => TRUE,
'type' => 'int',
'description' => 'The zero-based index of the page to get, defaults to 0.',
'default value' => 0,
'source' => array('param' => 'page'),
),
array(
'name' => 'tid',
'type' => 'string',
'optional' => TRUE,
'source' => array('param' => 'tid'),
'description' => t('An optional Term ID for the category.'),
),
array(
'name' => 'sort',
'type' => 'string',
'optional' => TRUE,
'default value' => 'points',
'source' => array('param' => 'sort'),
'description' => t('Sort field'),
),
array(
'name' => 'dir',
'type' => 'string',
'optional' => TRUE,
'default value' => 'DESC',
'source' => array('param' => 'dir'),
'description' => t('Sort direction'),
),
),
),
'actions' => array(
'add' => array(
'help' => 'Add or subtract a given amount of points for a user',
'file' => array('file' => 'inc', 'module' => 'userpoints_service'),
'callback' => 'userpoints_service_add',
'access callback' => 'userpoints_admin_access',
'access arguments' => array('add'),
'args' => array(
array(
'name' => 'uid',
'type' => 'int',
'optional' => FALSE,
'description' => 'A valid Drupal User ID.',
'source' => array('path' => 0),
),
array(
'name' => 'points',
'type' => 'int',
'optional' => FALSE,
'source' => array('param' => 'points'),
'description' => 'Number of points to add/subtract.',
),
array(
'name' => 'tid',
'type' => 'int',
'optional' => TRUE,
'source' => array('data' => 'tid'),
'description' => t('An optional Term ID for the category.'),
),
array(
'name' => 'operation',
'type' => 'string',
'optional' => TRUE,
'source' => array('data' => 'operation'),
'description' => t('An operation string for this transaction.'),
),
array(
'name' => 'description',
'type' => 'string',
'optional' => TRUE,
'source' => array('data' => 'description'),
'description' => t('An optional description of this transaction.'),
),
array(
'name' => 'entity_type',
'type' => 'string',
'optional' => TRUE,
'source' => array('data' => 'entity_type'),
'description' => t('An optional description of this transaction.'),
),
array(
'name' => 'entity_id',
'type' => 'int',
'optional' => TRUE,
'source' => array('data' => 'entity_id'),
'description' => t('An optional description of this transaction.'),
),
),
),
),
),
);
}